(Solved) Assertion failed on expression: 'gameObject.IsDestroying()' - possible causes?

Hello everyone,

I have a rather convoluted system of object destruction involving on-the-fly reparenting and rigidbodies creation/destruction, and I get following error when destroying objects:

As I understand there’s internal assertion call somewhere in Unity components, but there’s no stack trace on failed assertion so I can’t exactly understand what’s causing this. It seems like it’s raised on FixedUpdate after Update during which all destruction and creation took place - but that’s the extent of my attempts at isolating it.

1 Like

Managed to get to the bottom of this:

It was caused by following combination of events:
0) Setup is as follows: GameObject1 is parent of GameObject2. GameObject2 have active RigidBody on it (not sure if relevant but seems to affect this error).

  1. Destroy GameObject2 - simple destroy, not immedeate;
  2. In OnDestroy of GameObject2, change parent of GameObject1 (for pooling)

Solved it by placing GameObject1 instances in global query inside OnDestroy of GameObject2, and re-parenting them during next frame.