- Home /
OnTriggerEnter 's Not called at startup?
Problem: say you have two triggers overlapping one another when a scene first starts. How would you check if they're touching/overlapping without using OnTriggerStay?
(My reason to want to do this is because I am just trying to keep a track of what objects are currently near/touching one another in a list. Touching objects are added to the list in OnTriggerEnter, and removed in OnTriggerStay. That way I can use that list when I need it, and not be constantly updating).
I.e. ideally, we'd get at least one call of OnTriggerEnter if triggers are overlapping on startup.
Are there any easy work-arounds?
Answer by TheokieZA · Nov 27, 2010 at 08:13 PM
Cant you yield the call?
I'm not sure what you mean?
I'm kind of counting on the physics engine to tell me which triggers are actually touching.
Answer by Aubrey Hesselgren · Nov 27, 2010 at 11:48 PM
Huge hack, but I got around it by recording transform.position into a member variable "startPos" in Awake(), setting transform.position to transform.position + Random.insideUnitSphere * 1000.0f;
And then in Start() I did rigidbody.MovePosition(startPos);
That forces it to consider where it's moving to and triggers off the OnTriggerEnter call.
Also had to make sure that interpolation was off for that frame so that it just jumps straight to the first position, rather than colliding with anything inbetween (which happened because I have two of these dudes overlapping).
Your answer
Follow this Question
Related Questions
Newbie having problems with attaching cloth to a character. PLEASE HELP! 1 Answer
OnTriggerEnter/Exit not working 1 Answer
OnTriggerEnter Multiple Collisions Activating. I tried many variations, Please help (Java) 3 Answers
How do I switch from Character player to Airship Vehicle using triggers? 0 Answers