OnMouseExit fires every frame when the mouse is down?

I have a model with a rigidbody attached and I change the material in OnMouseEnter and OnMouseExit. It works correctly when I don't hold the mouse button down, but when I do have any mouse button held down and I drag over the object it flickers. Is this a known bug or am I doing something wrong?

Edit: added code

void OnMouseEnter()
    if (sCurrentHoverSlot == null)
        sCurrentHoverSlot = this;
        gameObject.renderer.material = GUIManager.instance().weaponSlotHoverMaterial;

void OnMouseExit()
    if (sCurrentHoverSlot == this)
        sCurrentHoverSlot = null;
        gameObject.renderer.material = GUIManager.instance().weaponSlotDefaultMaterial;
more ▼

asked Dec 16, 2010 at 11:08 PM

_Petroz gravatar image

3.9k 63 61 90

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

It's a bug that happens if you're using OnGUI.

As a side note, you don't need a rigidbody if you're just using OnMouseEnter/Exit, all you need is a collider. If you are using it as a moving object under physics control, never mind.

more ▼

answered Dec 17, 2010 at 02:34 AM

Eric5h5 gravatar image

107k 51 180 648

Thanks, if it's a known bug I can just live with it for now. I'm not using the rigidbody for anything except the mouse collisions. If i remove the rigid body OnMouseEnter and OnMouseExit no longer get fired.

Dec 17, 2010 at 03:55 AM _Petroz

Rigidbodies are only necessary for objects in motion under physics control. OnMouseEnter and OnMouseExit depend only on a collider present, not a rigidbody. They do fire without a rigidbody.

Dec 17, 2010 at 05:09 AM Eric5h5

That isn't the behaviour I'm seeing. I have appended the code to my post. Here is a demonstration: http://www.youtube.com/watch?v=FjM8fqAmVdo

Dec 18, 2010 at 11:25 AM _Petroz

@Petroz: Aha, the problem is that you're using a compound collider. This isn't a bug. By design, compound colliders act as a single collider when you add a rigidbody to the parent, and therefore only the root object will react to OnMouseEnter. If you add a rigidbody to the child, you break the compound collider; as the docs say, you should not parent rigidbodies together. So the rigidbodies have nothing to do with OnMouseEnter, but are rather changing how the colliders themselves work in the case of parent/child.

Dec 18, 2010 at 04:04 PM Eric5h5
(comments are locked)
10|3000 characters needed characters left

Do you have something inside any of the OnMouseDown/Over/Drag functions?

more ▼

answered Dec 17, 2010 at 01:52 AM

uhahaha gravatar image

432 6 5 19

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Dec 16, 2010 at 11:08 PM

Seen: 1657 times

Last Updated: Dec 18, 2010 at 11:26 AM