• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by SpoonyBard · Apr 14, 2010 at 07:26 PM · collidermesh

OnMouseDown() with a Mesh Collider?

Hi,

I'm working on a project that has house models, which are comprised of multiple meshes, each with their own mesh colliders and mesh renderers.

I have a script (that is confirmed working on anything with a Box Collider) that I want to apply to just a single mesh (outside lamps) of the house.

The script has an OnMouseDown() function, which is crucial. It won't work when applied to the mesh objects, but will work if I custom-fit a Box Collider over the object. This is a pain though, and won't work if the parts of the model aren't contiguous.

Is there a simple solution to this? Am I being stupid? Any help would be appreciated!

Thanks, SpoonyBard

EDIT: Turns out it might not be related to Mesh Colliders, as a Cube with a Mesh Collider works fine. Is there a setting to do with the model itself that I might be forgetting? The house and all of its parts seem to collide fine!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image alexnode · Apr 14, 2010 at 08:34 PM 0
Share

Could you describe a bit more what do you want to do with the mouse down, to see if we can help? You could add a mesh collider to any object by going to the menu - add component - mesh collider. If you want a trigger tick the isTrigger check box.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Molix · Apr 15, 2010 at 03:23 AM

When this sort of thing happens with us, it is typically because the collision mesh doesn't match up to the visual mesh. The most common causes: a rotation of one that is not applied to the other, or a scaling difference. Selecting the object in the hierarchy should highlight the collision in light green for a visual check.

Sorry if this is obvious, but it happens to us enough that I figured it was worth mentioning.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Zeroth · May 06, 2010 at 08:23 PM

The problem is that if you have a complex conglomeration of several meshes, when you click on one, it does do an OnMouseDown event... but it does not send that event upwards. So if you have a house composed of several meshes, then clicking on it is working as intended... but the top level parent is not receiving the click events.

A couple ways to solve this:

Make a simple script with a variable for the parent, then place the script on each child mesh. This script will simply have an OnMouseDown event that will find the key script on the parent, and call the relevant functions there.

Put the key script on every child mesh(not recommended for bigger meshes).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Matt-Face · Jun 03, 2013 at 01:50 PM 0
Share

@Zeroth

Thanks this comment helped me a lot!

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

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.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Is it possible to make thousands of colliders at once? 1 Answer

Ignore/Destroy then re-enable Mesh Colliders 3 Answers

Assign a Mesh to Mesh Collider Automatically 1 Answer

Why attach a kinematic rigidbody to a collider that moves a lot? 1 Answer

Runtime mesh generation 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges