Hey guys, just need a little help with collision detection between 2 GameObjects. I normally don’t have a problem but I’ve come across a scenario that doesn’t seem to work for me. Collision detection with an object inside of another objects hierarchy.
All the creation is done at runtime. Firstly I create an empty GameObject. This acts as a container for the other GameObjects I Instantiate. The prefab I use has the following setup. Its a cube, with a box collider with is trigger set to true. I parent these GameObjects with the main container once they are created by using,
block.transform.parent = container.transform;
I then have another external GameObject which is my hero. It is again a cube with a box collider and a rigid body. It also has a script attached to it which has the following simple OnTriggerEvent script.
void OnTriggerEvent(Collider other) {
print("blah");
}
Now I move the main container in my LevelManager script and watch for a collision in my scene window. I can see a collision happening but the on trigger event doesn’t fire.
The weird thing is if I add the Prefab without adding it to the Container GameObject and them play the OnTriggerEvent fires. When its inside of another GameObject it doesn’t work?
Am I missing something with the Collision detection with parented objects?
All I’m trying to do is work out if an object outside the Container of GameObjects(hero) collides with one of the GameObject’s inside the container.