• 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 SmokeyDB · Oct 21, 2013 at 03:26 AM · collisionontriggerexit

OnTriggerExit Inconsistent with multiple objects

I have a group of blocks that are supposed to vanish when the player collides with them. For this, I use OnTriggerEnter, and it works just fine. The issue comes when the player leaves the collision box of the block. 95% of the time, the OnTriggerExit runs and the block re-appears. For some reason, 5% of the time the blocks will not re-appear.

I'm just curious to see if anybody has any ideas. It's almost as if OnTriggerExit gets confused when it's called by multiple objects in quick succession.

The blocks are tagged as platforms and the player is tagged as player. Also, I'm using discrete collision and using a fixed timestep of 0.02.

Here is my vanishBlock Script:

#pragma strict private var animPlaying = false; private var delayedEnable = false; private var isIn = false;

function Start () { gameObject.GetComponent(AnimatedSpritesheet).columns = 8; gameObject.GetComponent(AnimatedSpritesheet).framesPerSecond = 0; gameObject.GetComponent(AnimatedSpritesheet).repeat = false; gameObject.GetComponent(AnimatedSpritesheet).SetFrameOrder([0]); }

function Update () { if (delayedEnable){
if (!isIn){ EnableCollider(); delayedEnable = false; } } }

function PlayAnimation () { if (!animPlaying){ DropCollider(); animPlaying = true; gameObject.GetComponent(AnimatedSpritesheet).columns = 8; gameObject.GetComponent(AnimatedSpritesheet).framesPerSecond = 8; gameObject.GetComponent(AnimatedSpritesheet).repeat = false; gameObject.GetComponent(AnimatedSpritesheet).SetFrameOrder([0,1,2,3,4,5,6,7]); } }

function PlayReverseAnim (){ gameObject.GetComponent(AnimatedSpritesheet).columns = 8; gameObject.GetComponent(AnimatedSpritesheet).framesPerSecond = 8; gameObject.GetComponent(AnimatedSpritesheet).repeat = false; gameObject.GetComponent(AnimatedSpritesheet).SetFrameOrder([7,6,5,4,3,2,1,0]); }

function DropCollider (){ yield WaitForSeconds (1.0); collider.enabled = false; yield WaitForSeconds (1.0); if (!isIn){ EnableCollider(); } else { delayedEnable = true; } }

function EnableCollider (){ if (!isIn) { PlayReverseAnim(); collider.enabled = true; } yield WaitForSeconds (1.0); animPlaying = false; }

function isInYes(){ isIn = true; }

function isInNo(){ isIn = false; }

Here is my vanishBlockCollider Script:

#pragma strict

function OnTriggerEnter (other : Collider){ if (other.CompareTag("Player")){ gameObject.SendMessageUpwards("PlayAnimation"); gameObject.SendMessageUpwards("isInYes"); } }

function OnTriggerExit (other : Collider){ if (other.CompareTag("Player")) gameObject.SendMessageUpwards("isInNo"); }

Comment
Add comment · Show 7
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 mattssonon · Oct 21, 2013 at 08:13 AM 0
Share

It's not because OnTriggerEnter (or whatever is initially hiding the block) gets called immediately after OnTriggerExit?

avatar image LijuDeveloper · Oct 21, 2013 at 09:04 AM 0
Share

Can you write sample code , it will help to find the problem in code

avatar image SmokeyDB · Oct 21, 2013 at 04:35 PM 0
Share

I don't think it is because the OnTriggerEnter is being called immediately after the OnTriggerExit. I'll add a yield before enabling the collider again to make sure though.

avatar image SmokeyDB · Oct 21, 2013 at 04:35 PM 0
Share

Also, I've added the code Liju. =)

avatar image SmokeyDB · Oct 21, 2013 at 05:10 PM 0
Share

I tried adding the yield before enabling the collider and that caused a few other blocks to not re-appear. Now I'm wondering if it has something to do with the yields I have in the DropCollider and EnableCollider.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by haim96 · Oct 21, 2013 at 10:33 AM

without your code it will be difficult to know what is wrong. but i suggest that you check that no other things beside your player is effecting the colliders. for example is the cubes collide with ground or each other and it make them disappear. for this you can give your player a TAG and for check it in OnTriggerExit.

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 SmokeyDB · Oct 21, 2013 at 04:38 PM 0
Share

The only other objects that could be colliding with the block are platforms or other blocks. The player and blocks are already tagged and the collider is already checking for the player.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

2D game object trigger 1 Answer

Character Controller not detected OnTriggerExit 0 Answers

Make text appear when object is clicked 2 Answers

Why does OnTriggerExit2D not fire when Kinematic Rigidbody Collider exits Trigger Collider? 2 Answers

Skined Cloth 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