Correctly migrate the host

Options

Hi, I'm trying to implement host migration, so I put this from the documentation in the INetworkRunnerCallbacks:


public NetworkRunner runnerPrefab;


public async void OnHostMigration(NetworkRunner runner, HostMigrationToken hostMigrationToken)

  {

    await runner.Shutdown(shutdownReason: ShutdownReason.HostMigration);


    var newRunner = Instantiate(runnerPrefab);

     

    StartGameResult result = await newRunner.StartGame(new StartGameArgs()

    {

      HostMigrationToken = hostMigrationToken, 

      HostMigrationResume = HostMigrationResume, 

    });


    if (result.Ok == false)

    {

      Debug.LogWarning(result.ShutdownReason);

    }

    else

    {

      Debug.Log("Done");

    }

  }


  void HostMigrationResume(NetworkRunner runner)

  {

    foreach (var resumeNO in runner.GetResumeSnapshotNetworkObjects())

    {

      if (resumeNO.TryGetBehaviour<NetworkPositionRotation>(out var posRot))

      {

        runner.Spawn(resumeNO, position: posRot.ReadPosition(), rotation: posRot.ReadRotation(), onBeforeSpawned: (_runner, newNO) =>

        {

          newNO.CopyStateFrom(resumeNO);

        });

      }

    }

  }


  public void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason)

  {

    if (shutdownReason == ShutdownReason.HostMigration)

    {

      // ...

    }

    else

    {

      // Or a normal Shutdown

    }

  }


the INetworkRunnerCallbacks and the Runner share the same game object, and inside the runnerPrefab variable I put another almost identical game object with another INetworkRunnerCallbacks attached.

now the host migration works, however, all network objects in the scene are destroyed, except the players, and I can't figure out what the reason is.

Can you help me?

Thank you.