• 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
Question by Geads · Sep 01, 2017 at 05:38 PM · 2dcollisiontriggertriggerstriggering animation box collider

OnTriggerExit2D not working, but OnTriggerEnter2D does???

Just as the title states. I have an enemy and when he collides with a boxCollider2D the OnTriggerEnter2D works, but I cant even get a Debug.Log("test"); to show up on an OnTriggerExit2D.

What gives???

Comment

People who like this

0 Show 0
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

5 Replies

· Add your reply
  • Sort: 
avatar image

Answer by benatfantasylabs · Sep 01, 2017 at 05:40 PM

Check your spelling and capitalisation

If that doesnt help you might need to paste some code for anyone to be able to help

Comment

People who like this

0 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 Geads · Sep 01, 2017 at 05:44 PM 0
Share

I added my code.

avatar image

Answer by Geads · Sep 01, 2017 at 05:43 PM

  public void OnTriggerEnter2D(Collider2D other)
     {
         if (other.tag == "Edge")
         {
             enemy.ChangeDirection();
             
         }
         if (other.tag == "JumpTrigger")
         {
             enemy.EnemyJump();
             Debug.Log("Jump Test - On Enter");
 
         }
         if (other.tag == "LandTrigger")
         {
             enemy.EnemyLand();
             Debug.Log("Land test - On Enter");
 
 
         }
     }
 
     public void OnTriggerExit2D(Collider2D other)
     {
         if (other.tag == "JumpTrigger")
         {
             Debug.Log("Jump Test - On Exit");
         }
     }

On Enter works, On Exit does not.

?????

Comment

People who like this

0 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 PWL_Para · Sep 01, 2017 at 05:50 PM 0
Share

Paste what change direction does?

avatar image benatfantasylabs · Sep 01, 2017 at 06:08 PM 0
Share

What does enemy.EnemyJump(); do?

Without seeing any code i would guess that it is because you are moving the collider out in the same frame (I dont think you can have an enter and an exit happen in the same frame so the exit gets missed)

You could try making the jump function set a member variable and in update in the next frame react to that

avatar image Geads benatfantasylabs · Sep 01, 2017 at 06:23 PM 0
Share

EnemyJump(); just sets jump = true; so the enemy jumps.

So the enemy hits a collider, jump = true; when the enemy is jumping they leave the collider so the OnTriggerExit2D should run, but it doesn't

avatar image

Answer by PWL_Para · Sep 01, 2017 at 05:47 PM

It is soo hard to answer with such little information... :(
There are soo many things to check. 1:Check which colliders are really used. 2:See if any colliders are getting Disabled/Becoming Non Trigger/Sizes/Changing Layers/ etc.. 3:Check if one of at least one rigid body stays active all along. 4:Check if script is enabled all along. etc...

Sooo soo many things could have gone wrong.

Comment

People who like this

0 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 Geads · Sep 01, 2017 at 06:04 PM 0
Share

If all the OnTriggerEnter2D's are working then why does it matter what is inside them? The script is enabled because the OnTriggerEnter2D's are working. Its the same collider, I don't understand why It works on the onEnter and not onExit. It's all the same colliders.

avatar image

Answer by Raimi · Sep 01, 2017 at 09:25 PM

Is your enemy actually leaving the the trigger area? if not, on trigger exit wont be called.

e.g. Enemy enters area, enemy is destroyed. Trigger exit wont be called.

e.g Enemy enters area, Trigger is destroy. Trigger exit wont be called.

e.g Enemy enters area, Passes through and out of area. Trigger exit will be called.

Comment

People who like this

0 Show 0 · 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

Answer by guilhermecorintho · Sep 05, 2019 at 02:04 AM

Try to change the place of " Debug.Log("Jump Test - On Exit");" to outside of your if condition [if (other.tag == "JumpTrigger")] to see if the problem is really if the OnTriggerExit2D call or it is up to your IF statement

Comment

People who like this

0 Show 0 · 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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

164 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 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 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 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 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 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 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 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 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

2D Triggers and Collisions not working as expected. 2 Answers

Collision returning an error 0 Answers

Collision Detection - Strange issues! Working when it shouldnt, not working when it should! 2 Answers

Detect a collision point, but allow pass through collider. 0 Answers

How to detect in grid of objects if one is destroyed while beside adjacent objects without rigidbody? 1 Answer


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