I have a gameobject following two connected splines. Splines are connected at runtime. When the object is destroyed I want to disconnect the splines. I have the following code;
When the code is called I get the following error;
Destroying components immediately is not permitted during physics trigger/contact, animation event callbacks, rendering callbacks or OnValidate. You must use Destroy instead.
UnityEngine.Object
estroyImmediate (UnityEngine.Object)
What checks do I need to do to make sure I can delete the connection?
Thanks
Code:
pooledObject.SplineController.Stop();
if (pooledObject.SplineConnection != null)
{
ObjectExt.Destroy(pooledObject.SplineConnection, false, false);
}
When the code is called I get the following error;
Destroying components immediately is not permitted during physics trigger/contact, animation event callbacks, rendering callbacks or OnValidate. You must use Destroy instead.
UnityEngine.Object

What checks do I need to do to make sure I can delete the connection?
Thanks