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 cassius · Mar 14, 2013 at 01:37 AM · rigidbodyontriggerenterontriggerexitmultiple objects

OnTriggerEnter, OnTriggerExit Work Only Once

I'm having a problem with the my triggers not being triggered more than once.

I have three types of objects which are instantiated and put into three pre-existing parents. Each of the three objects are instantiated multiple times (with unique names) and all put into their appropriate parents. Each has a collider (with Is Trigger selected) and a rigidbody attached. Example Hierarchy:

 OverallParent
 -Sides
 ---Side0
 ---Side1
 ---Side2
 -Guns
 ---Gun0
 ---Gun1
 ---Gun2
 -Selections
 ---Selection0
 ---Selection1
 ---Selection2

There is then one large collider set to Is Trigger, also with a rigidbody attached, which acts as the boundary of the playable area. If one of the instantiated objects goes outside, it is Destroyed.

However the both the OnTriggerEnter and OnTriggerExit only work for the first instantiated object which enters or leaves. All others are simply ignored for some reason. I have verified multiple times that every one of them has the same collider, rigidbody, and all other settings both before and after the first trigger occurs.

Does anyone have any ideas?

Comment
Add comment · Show 3
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 hnsmith · Mar 14, 2013 at 08:24 AM 0
Share

can you build a sharable project that reproduces this issue? It would help us perhaps identify the problem, and maybe the process of rebuilding a simple example that exhibits this behavior might help you see it yourself.

avatar image cassius · Mar 15, 2013 at 03:11 AM 0
Share

I'll see if I can put a sample together. But in the meanwhile, I think something really wonky is happening in Unity for me. I'm still trying to track down this problem and noticed something very strange. Here's a snipped of code.

 .....
 } else {
         print("true");
         print("upwards randomSideSize = "+randomSideSize);
         startPosition = startPosition - Vector3(0,randomSideSize,0);    // Set new start position for next instantiation
 }
 .....

$$anonymous$$y ter$$anonymous$$al output is as follows:

1) upwards randomSideSize = 3.550462 UnityEngine.$$anonymous$$onoBehaviour:print(Object)

2) A newSide position = (7.0, -46.9, -14.6) UnityEngine.$$anonymous$$onoBehaviour:print(Object)

What's really strange here is that the line 'print("true");' is completely ignored!? I've double clicked #1 in the console to be absolutely sure it was indeed the line directly after the print("true") statement. I really don't understand what's going on here but I have a feeling it's somehow related to my problem. In 20 years of coding I've never seen something quite like this.

avatar image hnsmith · Mar 15, 2013 at 03:56 AM 0
Share

is this snippet of code happening inside of a loop? A full project would really be helpful =], sorry I can't do more with just this much information. I agree something definitely looks wonky. If you push something to git let me know, I wouldn't $$anonymous$$d giving you a second pair of eyes.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by sparkzbarca · Mar 15, 2013 at 06:17 AM

your trigger shouldnt be the playable area it should be 4 areas outside of the area.

You define where you dont want them to go you dont spawn them inside the trigger

and use ontriggerexit.

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 sparkzbarca · Mar 15, 2013 at 06:19 AM 0
Share

I don't think triggers track multiple objects. they pass a single object to the function OnTriggerEnter not a list. I'm guessing that makes it impossible to track multiple objects but i'm not sure.

avatar image cassius · Mar 15, 2013 at 10:44 PM 0
Share

Thanks sparkzbarca. It looks like doing it the opposite way around fixed my problem. I'm guessing that when multiple objects are instantiated within the same frame, within a collider, that the collider doesn't register each individually.

avatar image
1

Answer by Eric5h5 · Mar 15, 2013 at 07:07 AM

Turn off "collapse" in the console, or if you're using Unity 4, keep collapse on and pay attention to the line count on the right.

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

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

13 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

Related Questions

OnTriggerExit doesn't fire when changing RigidBody (bug? feature?) 2 Answers

OnTriggerExit happens too soon! 1 Answer

OnTriggerEnter/Exit called unexpectedly 2 Answers

OnTriggerEnter works, OnTriggerExit doesn't 3 Answers

OnTriggerEnter function in c# 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