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
if (sCurrentHoverSlot == null)
sCurrentHoverSlot = this;
gameObject.renderer.material = GUIManager.instance().weaponSlotHoverMaterial;
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 OnMouseEnter and OnMouseExit no longer get fired.
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.
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
@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.
Answer by uhahaha
Dec 17, 2010 at 01:52 AM
Do you have something inside any of the OnMouseDown/Over/Drag functions?
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
No one has followed this question yet.
Changing the Mouse's Range for OnMouse events
Making a tray GameObject that slides out on mouse over
OnMouse events with overlapping colliders
Multiple GUI textures one script
Adding picture on top when hovering an object.