OnTriggerEnter not firing if I instantiate a GameObject completely inside another's trigger

I have the follow setup:

GameObject A, with a CharacterController, and a child GameObject Ac, containing a sphere collider (radius 10, for example purposes) with Is Trigger set to true.

GameObject B, with a CharacterController, a a child GameObject Bc, containing a sphere collider (radius 2) with Is Trigger set to true.

Ac and Bc both contain the same script that, for now, simply has a method for capturing OnTriggerEnter.

If A and B move towards each other OnTriggerEnter works fine. If I instantiate a copy of B such that the character controller is intersecting with Ac, OnTriggerEnter fires for both.

However, if I instantiate a copy of B such that the character controller of B is entirely contained within Ac’s sphere collider, things don’t work as expected. Sometimes Ac’s OnTriggerEnter fires, and sometime’s Bc’s OnTriggerEnter fires, but not both.

I’ve been trying to figure out why this is the case, or if there’s any workarounds. Any help would be greatly appreciated :slight_smile:

I know this is old, but in case some one is still looking for the answer.
One way I do it is to Disable and enable the collider right after instantiating it.

GameObject obj = Instantiate(prefab) as GameObject;
obj.GetComponent<Collider>().enabled = false;
obj.GetComponent<Collider>().enabled = true;

Hope this helps someone :smiley:

If a collider is already contained inside another collider, the OnTriggerEnter won’t fire.
The only trigger that is operating at this situation is OnTriggerStay.

Let me know if this answers your confusion.

I had the issue when i lay an item to the ground i instantinate it from prefab on the ground and then
i wanted the possibility to pick it up right again. The collider OnTriggerStay does not recognize it.
So i have a working workaround for this where i move the object with the collider a little bit after instantinating, so the collider will recognize it again.

Move the Object with the Collider like this.

transform.position = new Vector2 (transform.position.x+0.000001f, transform.position.y);