- Home /
Why does the Particle System restart when I unparent?
I'm trying to unparent a particle system from an object that's about to be disabled to ensure that the current particles persist. However the moment I try to unparent it, the particles from before are deleted and the particle system is reset to the beginning. This is the code I'm using to unparent it.
protected virtual void OnDisable()
{
if(BloodSplurt != null)
{
BloodSplurt.transform.SetParent(null);
}
}
Answer by AaronBacon · Aug 17, 2021 at 01:35 PM
From reading around, it seems to be that Unity still marks the object as about to be destroyed, so the particle system marks itself as ended before OnDisable is called, restarting it. So it seems the problem isn't to do with unparenting it, it's that the object is being "undestroyed" and the system resets because of it.
Only solution people have suggested is parenting the particles to an empty gameObject, though some of the threads I'm looking at are years old so could be outdated:
https://answers.unity.com/questions/930342/particle-system-resets-when-unparenting.html https://forum.unity.com/threads/particle-systems-particles-destroyed-when-changing-parent.435458/
Hey thanks. Moving it out of OnDisable worked. I was really thrown off because of the solution from this thread
https://answers.unity.com/questions/930342/particle-system-resets-when-unparenting.html
Guess we should be avoiding OnDisable and OnDestroy if we want particles to persist.
Your answer
![](https://koobas.hobune.stream/wayback/20220613041749im_/https://answers.unity.com/themes/thub/images/avi.jpg)