Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 GodlyPerfection · Nov 19, 2012 at 04:58 PM · instantiateprefabunity 4onmouseenterinconsistent

Inconsistent OnMouseEnter caused by Instantiate

Alright so I've been pouring over this issue for several hours now and double checked everything that I possibly know. Here is what is happening.

I'm working on a board game. I have the board spaces and pieces set to highlight OnMouseOver. The spaces have worked fine, and MOST of the pieces work fine. Pieces are created dynamically through instantiate at particular board spaces. Here are relevant details:

  • Pieces that are built from the same prefab are not consistent with each other; say I spawn two pawns, one works OnMouseOver and the other doesn't

  • Sometimes swapping to a different board space fixes it, sometimes it doesn't

  • I've double checked all colliders while debugging and they are still all there

  • There are no overlapping colliders getting in the way of mouse overs

  • Swapping the order of the piece spawning does affect which pieces work and which don't

  • Creating multiple lines of Instantiate changes which pieces work and which don't; there is no discernible pattern (if 4 pieces don't work, adding 4 more instantiates doesn't "push" the bad instances off of a stack)

  • All of the properties of instanced objects from the same prefab are all the same

  • Making all of the instancing happen from only one of the prefabs does not change anything (so it is just the act of instantiating)

Any ideas on what could be going on? I thought it was something wrong within my own code, but after isolating the problem the only line that changes anything is the instantiate lines and I've separated out the casting as well so it is just:

`Object obj = Instantiate(prefab);`

Duplicating that line creates different results based on how many lines there are. It is still consistent between runs (6 lines of instantiate causes the same pieces to not trigger OnMouseOver every time, but 7/8/9/etc lines of instantiate are all different).

Also yes the pieces must be instantiated at runtime as the pieces will eventually be chosen by the user to create their "team" and they can have multiples of a single piece. So having a pre-created pool of max number of multiples for each type of piece is unfeasible. I'm running on the latest version of Unity 4 Pro: 4.0.0f7.

EDIT: Another interesting detail... if I manually change the coordinates during debugging through the inspector and then change it back it starts working when I switch back to the game tab. ????? Does this make any sense?

EDIT2: None of my objects are on the IgnoreRacast layer.

EDIT3: Alright so changing the coordinates in the inspector fixes the issue, but moving it in the scene with the move tool does not fix it... very strange indeed.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by GodlyPerfection · Nov 19, 2012 at 08:56 PM

Found my problem... this can be closed. The issue was that I had generated a collider for the top level of the prefab and used the mesh from the child. What I didn't realize was that I also had generate colliders for my models on so the child also had a collider on it. Sometimes the Raycast would hit the top level object, but on the pieces that were broken it was hitting the bottom level and hence not triggering my top level OnMouseEnter code. :) Finally glad to have this fixed after 5 hours. This code is a beautiful thing:

 RaycastHit hitInfo;
 
 if( Physics.Raycast( Camera.main.ScreenPointToRay( Input.mousePosition ), out hitInfo )) {
     Debug.Log( "mouse is over object " + hitInfo.collider.name );
 }
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
0

Answer by faunaface · Apr 12, 2014 at 10:44 PM

I gave same issue, I have been spending a bunch of time on this so far. I do not get your solution though.. In My Prefab, I have a parent GameGameObject with couple childeren.. The Box Colldier2D is on the Outer GameObject, that covers all the children.

I double checked that the game object's "Is Trigger" is enabled and applied to all the PreFabs as well.

Could you explain what exactly is your issue and how did you fix it?

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

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.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How many time does a prefab takes to load?? 1 Answer

Updating a variable on a script in an instanced object 1 Answer

Why is transform.position of a prefab that's been instantiated different than a gameobject created on the scene, when they are in the exact same position? 1 Answer

Instantiate object 1 Answer

Prefab instantiated wrong scale on mobile 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