- Home /
OnTriggerEnter detects collision constantly after GO enters the box.
Hi,
I looked for a similar post but couldn't find any other problem like this. So here's another collision issue for you...
Situation:
I have a Box Collider that is a Trigger & a Rigidbody that is Kinematic attached to an object called "objA". (objA is attached to the camera.)
I also have another object with a Sphere Collider that is NOT a trigger and a rigidbody that is NOT Kinematic attached to, which I call "Pizza".
objA is very big and can encapsulate Pizza on collision. I added a print statement that prints the name of the collifing object on OnTriggerEnter and attached this to objA. (It prints many other objects' names on enter once the objects enters. That's working fine.)
My problem is:
However, when Pizza enters objA, the OnTriggerEnter event detects Pizza without stopping! Pizza is the only one that gets read countless times eventhough it never leaves the box after entering. So it enters the objA and stays there and I can see the print statement go crazy, running constantly!
How do I solve this problem? Why does this happen?
Thanks!
When I removed the Rigidbody from Pizza it starts acting normally. Appearing once in OnTriggerEnter. However I need the rigidbody on this object. There is not much code to show. There's only:
void OnTriggerEnter (Collider other) { print ("ENTER = name is " + other.gameObject.name); }
Answer by ttzilla · Apr 19, 2012 at 03:19 PM
I found the answer to my question and that was this line:
other.gameObject.SetActiveRecursively(true);
that I executed OnTriggerEnter. I'm guessing I was reactivating an object recurdively and upon REreactivation it enters the trigger again which causes an infinite loop.
Thanks for your time!
Hey can you please give an example cause I am too confused about this
Answer by ddf · Apr 23, 2015 at 09:09 PM
This can also happen if you have a CharacterController inside of a Trigger and are setting the CharacterController's radius every frame.
First of all, i really thank you for this information, very helpful. and second, updating any value not just the radius of the CC will cause this
Answer by fafase · Apr 19, 2012 at 08:34 AM
Could it be that you are misusing the collision functions.
OnTriggerEnter(other:Collider) means you don't want the physics engine to interact. So the 2 objects will simply pass each other through, still you can make things happen.
Try using OnCollisionEnter(other:Collision) if you want to object to collide and bounce without passing through.
Now, you need to decide what you want to happen,do you want object to get through it or not. Do you only want the pizza to bounce? Your objA is trigger so the physics engine is off, IsKinematic also disables the rigidbody collider. Meaning you have there a zone more than an object. The console prints because it reports a collision on every frame, now you would have to define some more behaviours once the collision happens.
What I want is them to overlap without bouncing, However, I want the Pizza to bounce against other objects in the game with rigidbodies and colliders. In other words I want ObjA to be the transparent/permeable screen that takes things in and out without bumping anything, while Pizza bumps at objects like him. I've tried OnCollisionEnter, but I will try again and report back.
When I use OnCollisionEnter it only detects when I bump into objects and push them around physically.
You might want to try and ignore collision http://unity3d.com/support/documentation/ScriptReference/Physics.IgnoreCollision.html
Answer by nathanvog · Oct 23, 2019 at 05:34 PM
It also seems to happen if your collider vertices are edited on every frame (by a Deformer for example).