Hi, I have a custom cylinder collider script attached to an object and I have it executing in edit mode so I can customize it and save it’s properties. Currently I re-instantiate the colliders every time I make a change and delete the ones left behind which is not efficient and I am planning on changing that. The issue is that for some reason, in the edit mode some colliders get left behind even though they shouldn’t and I have no idea what is causing that since it works just fine in play mode. Even the Transform.childCount property is returning values differentiating from what I’m seeing in the hierarchy.
Below is the part of the code that’s causing me trouble, is there anything I’ve overlooked?
Parent is defined as this.transform
void DestroyCylinderCollider()
{
//FIX: Leaves behind some colliders in Editor mode, but works perfectly in Play mode
for(int i = 0; i < Parent.chidCount; i++)
{
Transform colliderToDelete = Parent.GetC$hild(i);
if (colliderToDelete.name == "CyllinderColliderPart")
{
if (Application.isPlaying)
{
Destroy(colliderToDelete.gameObject);
}
else if (Application.isEditor)
{
DestroyImmediate(colliderToDelete.gameObject);
}
}
}
}