• 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 nopogo · Apr 09, 2013 at 02:13 PM · rigidbodycolliderontriggerentermesh colliderontriggerexit

OnTriggerEnter works, OnTriggerExit doesn't

The player object has a gameobject with a small collider cube (set as trigger) at eye height. The following script is attached to that object:

     // Use this for initialization
     void OnTriggerEnter(Collider trigger ) {
         if (trigger.gameObject.tag == "flooder" && !playerStats.m_headUnderWater){            
             Debug.Log("head under water");
             playerStats.toggleUnderWater(true);
         }            
     }
 
      void OnTriggerExit(Collider trigger) {
          Debug.Log("LeftTrigger!!!");
          Debug.Log(trigger.gameObject.tag);
          Debug.Log(trigger);
          if (trigger.gameObject.tag == "flooder"){
              Debug.Log("head left water");
              playerStats.toggleUnderWater(false);
          }        
     }

This is supposed to detect if a players head is underwater to trigger drowning.

The on trigger enter works fine, but on trigger exit will never register (not even the debug statements)

The body of water has a kinematic rigid body and a mesh collider set (also with trigger = true) to make collision possible and they are both in a layer that detects collision with the other layer. Tried setting the rigid body collision detection to continuous but even that did nothing.

Any help is appreciated!

Comment
whydoidoit
dpk
IASEnvy

People who like this

3 Show 15
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 deltamish · Apr 09, 2013 at 04:14 PM 0
Share

hi try using trigger.collider.tag and

try removing if (trigger.gameObject.tag == "flooder"){ in OnTriggerExit and just use

 playerStats.toggleUnderWater(false);
avatar image nopogo · Apr 09, 2013 at 05:54 PM 0
Share

Not even the debugs get printed, so it's not in the if statement

avatar image sdgd · Apr 09, 2013 at 07:52 PM 0
Share

watch your collider of water when you jump out

  • maybe you are draging colider with you

  • maybe you delete the colider

  • maybe you make water false before you get out I don't know how other scripts go

  • do you really jump out or just swim to the surface?

  • what happens if it's not kinematic?

it shouldn't move anyway as it's trigger so collider never colides because it's trigger so does not listenes to forces I think

avatar image nopogo · Apr 10, 2013 at 08:34 AM 0
Share

So after watching the collider it is not reacting to the impact with the player. The collider is definitely there. Switching kinematic changes nothing. The water rises with 0.01 each fixed update. But so slow that after the head "submerges" a jump clears the collider box from the collider mesh of the water.

I also tried adding oncollisionenter,exit, stay and ontrigger stay. Nothing gets printed/triggered after ontriggerenter :(

avatar image whydoidoit · Apr 10, 2013 at 12:10 PM 1
Share

Nope - everything that moves needs to have a rigidbody or it's collision information may not be updated - plus you get a lot of performance warnings.

Show more comments

3 Replies

  • Sort: 
avatar image
Best Answer

Answer by nopogo · Apr 12, 2013 at 09:11 AM

Found out that box colliders work in this setup, but mesh colliders do not. I'm thinking about submitting a bug report to unity

Comment
VivekD
pgomes

People who like this

2 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 whydoidoit · Apr 12, 2013 at 09:40 AM 0
Share

MeshColliders are generally a nightmare - they suffer from back face culling and are 1 directional - these things are documented in the Unity Docs but the practical experience of them can seem different.

avatar image

Answer by m.alekseev · Apr 09, 2013 at 03:49 PM

Maybe your rigid body falls asleep?

Comment

People who like this

0 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 nopogo · Apr 09, 2013 at 05:55 PM 0
Share

This is literally 1 second after ontriggerenter, I jump in water and the ontriggerenter gets registered. Then jump out but nothing

avatar image nopogo · Apr 11, 2013 at 10:22 AM 0
Share

to be sure i also set the rigidbody asleep timer to infinite in physics settings

avatar image

Answer by Er_ellison · Sep 17, 2017 at 11:34 AM

No , You wrong
I had the same problem but , think a little bit about it !
when you disabling that object while it entering to the area , YOU DISABLED IT , means that there is no active collider on scene that determines the OnTriggerExit !
if you use SetActive to disable the object that you want , Completely Wrong , You can use :

 yourObject.transform.localScale = Vector3.zero;

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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

OnTriggerEnter/Exit called unexpectedly 2 Answers

OnTriggerEnter, OnTriggerExit Work Only Once 2 Answers

Rigidbody + Multiple Trigger Colliders - OnTriggerEnter - Get which Collider triggered the event issue 1 Answer

Make object react to certain triggers only 1 Answer

Problem using trigger to set gameobjects active 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