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
4
Question by antx · Feb 09, 2013 at 12:45 AM · gameobjectdestroyontriggerexitintersection

OnTriggerExit not called on Destroy()

I instantiate a gameObject that immediately intersects with another gameObject. For both OnTriggerEnter is being fired. When I now destroy one of them, OnTriggerExit is not being fired on the one that is still there. Is this a bug or does this count as intended?

I need to get notice of the fact that the intersection no longer persists, and OnTriggerExit would have been handy here.

Is there another way to do this?

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 felixmann · May 27, 2017 at 03:09 AM 0
Share

This was a bug that has been fixed in Unity 5.6.

5 Replies

· Add your reply
  • Sort: 
avatar image
13

Answer by Ghopper21 · Feb 09, 2013 at 05:04 PM

This is almost certainly intended, as after you destroy the object there's no Collider component left to pass to the other object's OnTriggerExit function.

Here's a simple way to handle it, by putting your exit trigger logic in Update where you can check whether the triggering object has been destroyed:

 boolean triggered = false;
 Collider other;
 
 void OnTriggerEnter( Collider other )
 {
     triggered = true;
     this.other = other;
 
     // put other enter trigger logic here
 }
 
 void Update()
 {
     // check if we've been triggered but the other object has been destroyed 
     if ( triggered && !other )
     {
         // put exit trigger logic here
     }
 
     // put other update logic here
 }
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 antx · Feb 09, 2013 at 05:23 PM 0
Share

Okay, this seems to be a clean way to do it. Thank you.

avatar image Mesuko · Jul 23, 2016 at 10:44 PM 0
Share

I saw the date, but i need to thank you for the reply. You method fix my problem.

avatar image mjonasz · Jan 25, 2019 at 06:16 PM 0
Share

Had the same problem - thanks for the solution!

avatar image
1

Answer by RodrigoAbreu · Aug 05, 2018 at 06:53 PM

This bug seems to be back in Unity 2018.2.0f2, but I worked around it by implementing observers, so I notify the objects interested in the subject's status, including when it's destroyed.

Comment
Add comment · Show 2 · 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 Laguna_Seca · Feb 12, 2019 at 03:17 PM 0
Share

This shit is in Unity 2018.3.5f, although maybe it should work?

avatar image hottabych · Mar 29, 2019 at 11:33 AM 0
Share

2018.3.10, the same issue

avatar image
0

Answer by pad406 · Feb 09, 2013 at 12:55 AM

Sorry, dont know if it's a bug or not. As an alternative you could use sendmessage or broadcastmessage

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 antx · Feb 09, 2013 at 09:47 AM 0
Share

I guess it is not triggerd because the OnTriggerExit() would not have a parameter anymore since the other object does no longer exist. (OnTriggerExit hads over the collider of the object that caused the collision).

I´m thinking of moving the object very far away first and then call Destroy() on it. But I´m not sure if this will be reliable (ti$$anonymous$$g).

avatar image pad406 · Feb 09, 2013 at 02:09 PM 0
Share

Should work do a delayed destroy of you're concerned about ti$$anonymous$$g

avatar image $$anonymous$$ · Feb 09, 2013 at 02:26 PM 0
Share

hm... OnTriggerStay(), and check if the other's still there? OnTriggerExit() won't be called because that's a kind of collision, just a "negative" one.. you can't compute collision with an object marked for deletion, there would be no point in calling Destroy() then. You can use a Send$$anonymous$$essage although an event would be better.. Any object could subscribe to any other object to get notified of it's destroyment :)

avatar image
0

Answer by felixmann · May 27, 2017 at 08:44 AM

This was a bug that has been fixed in Unity 5.6.

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 amitDklein · Sep 19, 2021 at 09:56 AM

I just use

  this.GetComponent<SphereCollider>().radius = 0f;
  Destroy(this.gameObject);

Then when the radius it 0 the collider exit before you destroy it

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 Ryukai3 · Apr 09 at 09:27 AM 0
Share

I dont think that this work.

When you reduce radius/size to 0 it will trigger a OnTriggerExit event but also a OnTriggerEnter event subsequently.

So -1 +1 = 0, no effect.

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

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Destroy object when transform.position.x > 10. 1 Answer

Destroy(gameObject) does not work 2 Answers

Placing a cube on the face of another 4 Answers

Collision Detection for a Prefab? 3 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