What I used to do is something like this, I know it is the same as using the private static state, actually worse because it is even slower, but I just don’t like statics at all, I got traumatized thanks to old Unity official tutorials
// PRIVATE STATE
bool hasSpawned = false;
public bool GetHasSpawned { get => hasSpawned; }
// PRIVATE
private void Awake()
{
foreach (PersistentObjectSpawner pOS in FindObjectsOfType<PersistentObjectSpawner>())
{
if (pOS.GetHasSpawned && pOS != this)
{
Destroy(gameObject);
return;
}
}
SpawnPersistentObjects();
hasSpawned = true;
DontDestroyOnLoad(gameObject);
}
I’ve also seen some crazy “singletons” using ScriptableObjects.