• 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 nelson · Nov 17, 2010 at 04:33 AM · instantiation

instantiation, OnMouseDown function

The original object's OnMouseDown function works fine but when I instantiate the prefab at run time, it doesn't. I have other objects being instantiated and there OnMouseDown works fine. Any ideas? I've tried adding a rigid body to the instantiated object but get an tensor error.

Am I forgetting something?

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 StephanK · Nov 17, 2010 at 08:23 AM 0
Share

Could you post the code you are using? Is the function called at all? Is the prefab missing a collider?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by denewbie · Nov 17, 2010 at 08:21 AM

If possible we'll need to take a look at your script but at mean tine, Here are some basic stuff you can check for:

1) Did you rename the prefab correctly? ( If you haven't renamed it it'll carry the same name but with an additional "(clone)" concat to it ) as the back. The idea hare is that we need to make you're you're calling the correct object.

2) If you're refering to the created prefab object by hard coding the name in the mouse down script then you might be calling the original or first prefab initiated in your script with the same name. The idea once again is to make sure you're calling the correct object.

3) Check if your the the script you care concerned with is attached and saved as part of the prefab.

4) Next lets check if the mouse down was even being called in the first place. To do this i suggest we could place a print statement in the mouse down event like this: print("Mouse down was detected"); --- so we can know for sure it was called.

5) If step 4 shows that it was called then you can be sure that your object and every thing works fine. The problem probably lies and some "if - else" statement in your mouse down code segment. You only need to place that print statement in each segment to test if they were correctly called at the given conditions and alter those conditions that are wrong.

Once again its better if you could share a little of your code if its alright with you.

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 denewbie · Nov 17, 2010 at 08:23 AM 0
Share

By the way I don.t think its got anything to do with having a rigid body. In unity at least, you only need a collider to detect a mouse down event. Rigid bodies are only required for inter game object collision events.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Type casting error while instantiating. 1 Answer

Understanding Prefabs + Player Spawn Points 2 Answers

Object reference not set to an instance of an object error. 1 Answer

How to instantiate an object at mouse position? 1 Answer

UI: Creating UI based on many strings 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges