Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by WarKarma · May 15, 2011 at 03:10 AM · collisioninstantiateoncollisionenter

OnCollisionEnter doesnt work when instantiated

Hi,

I have this strange problem with collision detection. The "OnCollisionEnter" works fine if it's attached to a gameobject which I put into the Scene manually; however if I want to instantiate the same gameobject's prefab (example: by pressing a button) the gameobject prefab is instantiated, but the collision doesn't work anymore.

WTH? Help please p.s. I have tryed the OnCollisionStay, but it didnt help :(.

The code (enemy):

var BoomExplosion : GameObject;

function OnCollisionEnter (TriggerEnter : Collision) { if(TriggerEnter.gameObject.name == "BoomExplosion(Clone)" || TriggerEnter.gameObject.name == "BoomExplosion") {
Instantiate(SpawnExplosion, gameObject.transform.position, gameObject.transform.rotation); Destroy(gameObject);
} }

Comment
Add comment · Show 2
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 Mirzero · Aug 11, 2012 at 06:17 PM 0
Share

It's not very helpful, but I have this exact same problem. And previously I was instantiating the prefabs and it worked fine.

I can't see where I've changed anything, and on inspection the prefab I put in the scene manually is absolutely identical to the one I instantiated.

avatar image LukaKotar · Jul 03, 2014 at 10:12 PM 0
Share

I feel the need to bump this question, as I am faced with the same issue. I have a little side project (not a game, but a fancy 3D program) where I depend a lot on instantiation. I need to check for collisions between these instantiated objects.

An OnCollisionEnter function with nothing but a debug statement proves it's not working. All objects carrying a collider also have a rigidbody attached, as I am moving them at runtime.

They are colliding, 100% sure (the second "Click to edit" text object is instantiated during runtime): screenshot

screenshot 2014-07-04 00.10.02.png (19.4 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by nyanko · Jul 04, 2014 at 03:32 AM

Why don't you judged by GameObject's tag name?

 var BoomExplosion : GameObject;
  
 function OnCollisionEnter(TriggerEnter : Collision) 
 {
     if (TriggerEnter.gameObject.tag == "your tag 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How can I keep track of score without each new basketball shot reseting my points? 1 Answer

Collision between two instances of the same object 1 Answer

OnCollisionEnter not triggering when two rigidbody collide via Instantiate 1 Answer

How can I keep track of score without each new basketball shot reseting the points? 0 Answers

I don't think I get collision box, can someone help? 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