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

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

Assertion failed on expression: gameObject.IsDestroying()’

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.

Managed to get to the bottom of this:

It was caused by following combination of events:

  • 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).
  • Destroy GameObject2 - simple destroy, not immedeate;
  • 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.