- Home /
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; } }
Answer by Eric5h5 · Dec 17, 2010 at 02:34 AM
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.
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 On$$anonymous$$ouseEnter and On$$anonymous$$ouseExit no longer get fired.
Rigidbodies are only necessary for objects in motion under physics control. On$$anonymous$$ouseEnter and On$$anonymous$$ouseExit depend only on a collider present, not a rigidbody. They do fire without a rigidbody.
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=Fj$$anonymous$$8fqAmVdo
@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 On$$anonymous$$ouseEnter. 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 On$$anonymous$$ouseEnter, but are rather changing how the colliders themselves work in the case of parent/child.
Answer by uhahaha · Dec 17, 2010 at 01:52 AM
Do you have something inside any of the OnMouseDown/Over/Drag functions?
Your answer
Follow this Question
Related Questions
Can't seem to get OnMouseExit and Destroy(GameObject) to work properly 1 Answer
OnMouseEnter/Exit not working when pressing button to advance scene 2 Answers
Instantiate object OnMouseOver, then delete the instantiated object OnMouseExit. 1 Answer
OnMouseDown 2 Answers
Change cursor on OnTrigger 0 Answers