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 42p · Jan 31, 2014 at 12:17 AM · ontriggerenterbug-perhapsontriggerexitcollider 2d

Trigger actions when avatar enters/exists area

I had got a 2D project in the latest Unity3d. I tried it with overlapping BoxColliders and a single polynomCollider. The avatar has got a CircleCollider

I want to have actions when an avatar (Sprite) enters or exits a certain area (the collider of another Sprite). I do this by incrementing a counter in OnTriggerEnter() and decrementing in OnTriggerExit(). By writing the colliderCounter onto the Console, you will see that moving the avatar in out from the collider the colliderCounter can go negative, or grow over the number of colliders… The trigger functions do not get called the right amount…

Am I missing something? Is there a better way to implement this functionality? Is it a bug in Unity? Is that another way to implement this functionality so that I can work around the bugs? (I'm in a hurry, rather would not wait for a bug fix)

Update: Here's some of my script attached to the avatar:

 void OnTriggerEnter2D(Collider2D collider)
 {
         colliderCounter++;
     Debug.Log (colliderCounter);
 }
     void OnTriggerExit2D(Collider2D collider)
 {
         colliderCounter--;
     Debug.Log (colliderCounter);
 }

I see normal things on the console for a while: 0,1,2,3 (this a case with 3 overlapping box colliders) After moving in and out for a while, it I can see -1,-2, or 4,5… These show that some of the trigger actions do not happen.

The same problem exists if I use one polygoncollider.

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 sdgd · Jan 30, 2014 at 05:35 PM 0
Share

include some code.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Supercrusher9000 · Jan 31, 2014 at 01:58 AM

Are you sure that if you are using OnTriggerEnter() that the colider is checked as trigger? Also make sure that there is a colider on your avatar.

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 42p · Jan 31, 2014 at 07:07 AM 0
Share

Yes, the collider of the areas are checked as trigger. $$anonymous$$y avatar also has a collider, and the script containing the OnTriggerEnter() and OntriggerExit() functions. The avatar also has a rigid body attached.

I see the OnTriggerExit() and OnTriggerEnter() events working as expected for a while, but after moving in and out for a while it gets out of sync… I'll add a piece of my script to the original post.

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

20 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

Related Questions

walk through an object once 0 Answers

Can someone please tell me why this code isn't working? 1 Answer

OnTriggerEnter function in c# 0 Answers

Make object react to certain triggers only 1 Answer

OntriggerEnter / Stay with the same Gameobject tags 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