Hi
I have a problem. Might be a bug
I have a gameobject (rock) with a spherecollider. This is in layer “Collectables”.
This gameobject have a empty childobject (RangeCollision) with its own spherecollider. This is in layer “RangeTriggers”.
I have an object which must react to collision with the rock (But not the rangecollider), which is placed in layer “TriggerTargets”.
I have then used the “layer collision matrix” to make sure that “RangeTriggers” does not collide with “TriggerTargets”.
This is the code for the object which must react when the “Rock” collides:
void OnCollisionEnter(Collision collision)
{
Collectable newCollectable = (Collectable)collision.collider.gameObject.GetComponent(typeof(Collectable));
if (newCollectable != null)
{
addWeight(collision.collider.rigidbody.mass);
newCollectable.DestroyMe();
}
}
When drag my prefab from project ressources the above code works every time.
But if i copy one of the prefabs using ctrl-c/v then it only works approx 50% of the times. The other times the collider in OnCollisionEnter is the spherecollider of the childobject (Which should not collide, as set in the collision matrix)
I have a feeling that children perhaps inherits layerinformation from parent when copied…but i’m having a hard time figuring it out.
If these ramblings has made sense to anybody I would love to hear from you