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
0
Question by d112570 · Nov 14, 2013 at 12:02 AM · collidertriggerparentdisappear

GameObject disappears when enabling Trigger

I have a Parent GameObject which I added a collider, and his grandchild has also a collider, when I enable the collider trigger of his grandchild, the parent GameObject disappears? Is this a bug? if not how would you go and fix it, so it does not disappear.

Comment
Add comment · Show 3
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 Aspirer · Nov 14, 2013 at 12:04 AM 0
Share

Is the parent object set to die/destroy itself on a collision? If so, are these two colliders in contact?

avatar image clunk47 · Nov 14, 2013 at 12:06 AM 0
Share

You're using a script somewhere I'm sure. Post the script please.

avatar image d112570 · Nov 14, 2013 at 12:11 AM 0
Share

You may be right, the grandchild does have this script. I want the asteroid to destroy and not the parent planet. I need to find out why the planet is being destroyed.

 using UnityEngine;
 using System.Collections;
 
 public class CollisionDetecter : $$anonymous$$onoBehaviour {
     
     public GameObject explosion;
 
     void OnTriggerEnter(Collider asteroid) {
         
         var spawnSpot = asteroid.transform.position;
         Destroy(asteroid.gameObject,0.01f);
         
         GameObject newObj = Instantiate(explosion, spawnSpot, Quaternion.identity) as GameObject;
         newObj.transform.parent=transform;
         newObj.tag = "Clone";
         
     }
 }

1 Reply

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

Answer by d112570 · Nov 14, 2013 at 12:27 AM

I told it to avoid its grandparent. Here's the new code.

 void OnTriggerEnter(Collider asteroid) {
         
         if (asteroid.name != transform.parent.parent.name) {
         var spawnSpot = asteroid.transform.position;
         Destroy(asteroid.gameObject,0.01f);
         
         GameObject newObj = Instantiate(explosion, spawnSpot, Quaternion.identity) as GameObject;
         newObj.transform.parent=transform;
         newObj.tag = "Clone";
         }
     }
Comment
Add comment · Show 3 · 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 d112570 · Nov 14, 2013 at 12:29 AM 0
Share

Had it tested and it works. Asteroids can hit planet, and Asteroid destroyed and debris appear.

avatar image ThePunisher · Nov 14, 2013 at 12:38 AM 0
Share

Nice, that makes sense. Although, that means that the OnTriggerEnter method is getting called repeatedly because it's detecting a collision and that's probably not performance friendly. Think about it happening when you have multiple instances of this going on.

avatar image d112570 · Nov 14, 2013 at 12:51 AM 0
Share

It only gets called when I visit this planet and there is a Asteroid Script attached.

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

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

When collider enters trigger, colliders parent = triggers parent 1 Answer

Can't click gameobject when over another trigger? 1 Answer

How to prevent a game object from colliding with its parent 2 Answers

Parent Script accessing Child components 1 Answer

Trigger BoxCollider Fails to Move With GameObject After Resize 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