Calling Destroy(gameObject) in GlobalEventListener Awake() causes error

I have some simple singleton DDOL GlobalEventListeners eg:
public class RaceManager : Bolt.GlobalEventListener {
 
    public static RaceManager instance;

    public override bool PersistBetweenStartupAndShutdown()
    {
        return true;
    }

    public void Awake()
    {
        if (instance == null)
            instance = this;
        else if (instance != this)
            Destroy(gameObject);
    

When Destroy is invoked I get:
InvalidOperationException: Node is not in this list
BoltDoubleList`1[BoltInternal.GlobalEventListenerBase].VerifyInList (BoltInternal.GlobalEventListenerBase node)
BoltDoubleList`1[BoltInternal.GlobalEventListenerBase].Remove (BoltInternal.GlobalEventListenerBase node)
BoltInternal.GlobalEventListenerBase.OnDisable ()
UnityEngine.Object:Destroy(Object)

How to avoid this error?

Comments

  • I'm testing this in a new project but can't reproduce the error, can you provide some steps or email us a project?
  • If the server disconnects I want the client to return to the home scene (which has the above DDOL Racemanager).

    In BoltShutdownBegin() on the client I have SceneManager.LoadScene(0);
    When scene 0 loads and RaceManager.Awake() is called on a new instance it attempts to destroy itself but fails due to the above errors which are called 3 times for the 3 such GlobalEventListeners that I have.

    I tested without PersistBetweenStartupAndShutdown() but this makes no difference.

    I can presumably overcome this by having a 'headless' opening scene for my DDOL that is never returned to so Destroy is not called,
    or by putting my GlobalEventListeners in [BoltGlobalBehaviour],
    but I would like to know what is happening. If a GlobalEventListener is destroyed in Awake will there always be errors or have I misunderstood something?
  • The errors still occur if I delay returning to the home scene until BoltShutDownDone:

    public override void BoltShutdownBegin(Bolt.AddCallback registerDoneCallback)
    {

    //SceneFade.GoToHomeScene();

    registerDoneCallback(() => {
    SceneFade.GoToHomeScene();
    });
    }
  • The error does not occur if I call BoltLauncher.Shutdown();

    It does occur on the client when the server closes unexpectedly and the client responds by shutting down.