Destroying parent but keeping child, but on scene load

Hello,

I am having a problem with keeping child objects after their parent is destroyed on scene load.

I have an object pool of decals that are all contained in a root that has been set to DontDestroyOnLoad. These decals can get attached to objects in my scene by parenting them to the object. When the object they are attached to gets destroyed I want the decals to be moved back into the original root rather than getting destroyed with the object. I do this by adding a script called DestroyMessenger to the parent:

    public class DestroyMessenger : MonoBehaviour
    {
        /// <summary>
        /// Called when this object is about to be destroyed.
        /// </summary>
        public event Action OnDestroyed;

        private bool suppressDestroyEvent;

        private void OnApplicationQuit()
        {
            suppressDestroyEvent = true;
        }

        private void OnDestroy()
        {
            if (!suppressDestroyEvent && OnDestroyed != null)
                OnDestroyed.Invoke();
        }
    }

My decals can subscribe to the OnDestroyed event and get moved back into the pool before they are destroyed.

However, this does not appear to work with scene loading. The OnDestroy message and event is sent correctly by the parent, but the decals still get destroyed regardless of my attempt to move them back into the pool in DontDestroyOnLoad land.

Is there a way around this, or is it perhaps a bug? Or am I going to just have to potentially re-instantiate decals in my pool on scene load?

Thanks.

In your scene loader you add an event that listeners can subscribe to. Just before calling Load or LoadAsync you trigger the event and your objects will be safely released to their pool (at the condition that they respond immediately and non asynchronously to the event).

Unfortunately the system I am working on is a generic asset, and so I can’t really hook into the scene loading.

I can scan my pool(s) for null objects and recreate them, and since that would happen on scene load I think I can get away with whatever performance hiccup there may be. I was just hoping there was an alternative.