Destroy GameObject inconsistent with Instantiated children
Hi, I'm struggling a lot with this one.
I have an instantiation script on a Spawnpoint gameobject which is creating moving child prefab gameobjects with a particular tag (eg platformparent). These platformparents have child gameobjects in them, so the hierarchy ends up like this:
SpawnPoint ---> platformparent (moving) ----------> platform
The same script will also create another prefab gameobject with a script that will destroy the platforms (platformdestroyer). So the hierarchy will then look like this:
SpawnPoint ---> platformparent (moving) ----------> platform --->platformdestroyer
I'm certain the two objects definitely collide, and both have box colliders with "is trigger = True", and the platformparent has the correct tag per the script (platformparent)
My Destroy Script is:
void OnTriggerEnter (Collider other)
{
Debug.Log ("COLLISION "+other.gameObject);
if (other.gameObject.tag == "platformparent") {
Destroy (other.gameObject);
Debug.Log ("Object was destroyed: "+other.gameObject);
}
I never see either of the debug logs fire when my platformparents collide with the platformdestroyer, however i will see some other objects fire off the first debug message, but NOT ALL. I have tested an example where I collided with another object which was a child of a different parent which triggered the Collision debug message, however when I de-parented the SAME OBJECT, it never generated the Collision.
All I can think at the moment is that the script isn't quite honouring the collision if it happens at the "wrong" point in the hierarchy. Is that something that happens?
Would appreciate some help on this one. Got me stumped, and can't seem to quite find a similar scenario here.
Answer by milligna · Apr 14, 2017 at 05:31 AM
OK.... I've already made some progress - it seems that the OnTriggerEnter (Collider other) is only being called if the other object has a RigidBody...
Turns out had I read the manual, I would have spotted this: "Notes: Trigger events are only sent if one of the Colliders also has a Rigidbody attached."
Sorry for wasting time.
Your answer
Follow this Question
Related Questions
Car will only turn right (& ignored collders) 0 Answers
Why object's doesn't stop on collision enter? 0 Answers
Which object needs to be the trigger? 2 Answers
Per Frame BoxColliders? 0 Answers
Why is my trigger collider acting like a normal collider? 1 Answer