Trigger or Colission not work if inside volume

Hello, there!

I found that OnTriggerEnter/Stay/Exit and OnColissionEnter/Stay/Exit not work when object1 instantiated inside collider of object2. When its colliders not intersect on spawn moment all works great. Easy to understand why :slight_smile:

The only way to check if one object still near to spawned point is Vector3.SqrMagnitude(pos1,pos2). Not bad, but this need Update() :frowning:

Any other way to solve this problem with triggers?

For now I create several colliders on spawn point, when new object appear and start move it will intersect with one of those volumes. But … if object has great size, it intersects with all colliders at once and this approach not work universally :slight_smile:

Use OnTriggerStay or OnCollisionStay. This is called every fixed update that the colliders are in contact. At least one needs a [non-kinematic - or kinematic] rigidbody. OnTriggerStay is less efficient than OnTriggerEnter, of course, because it runs every fixed update instead of just once.

You could possibly use the Bounds of your colliders. Whenever you need to check if it’s inside your triggers, you just use collider.bounds.Intersects(otherBound) You will only need two objects with colliders. No rigidbodies are needed if that is a problem for any reason.