#DriverMigrationSystem Netcode for Entities

1 messages · Page 1 of 1 (latest)

vital ravine
#

Hello!

Reading the documentation, DriverMigrationSystem is used to migrate between worlds while maintaining a connection.
When I attempt to use this system on the client, I get some issues.

I tried using a similar setup the documentation described, and it does not seem to work properly.

  DriverMigrationSystem migrationSystem = default;

  foreach (var world in World.All)
  {
      if ((migrationSystem = world.GetExistingSystemManaged<DriverMigrationSystem>()) != null)
          break;
  }

  var source = NetcodeBootstrap.ClientWorld;

  var ticket = migrationSystem.StoreWorld(source);
  source.Dispose();

  var newWorld = migrationSystem.LoadWorld(ticket);
  setup.InitializeClientWorld(newWorld);

At first I got a null reference error, so I checked, DriverMigrationSystem is not automatically added.
Without much more detail in the docs, I assumed I just needed to add the system when I create the world.

After doing that, the error was solved, but I get a new error:
ApplicationException: The driver contains no valid BackupWorld to migrate from.

Not sure where to go from here, thought of doing it manually by moving network entities myself to the new world, but I don't know what entities are required to do this.
Any ideas?

For reference:
https://docs.unity3d.com/Packages/com.unity.netcode@1.11/manual/client-server-worlds.html#world-migration

sharp tartan
#

Is this for host migration or for moving to a different server?

vital ravine
# sharp tartan Is this for host migration or for moving to a different server?

This is for migrating to a different World (while maintaining a connection to the same server)
I.e LobbyWorld -> GameplayWorld

I did end up figuring it out, not sure if its perfect but it works:

 var source = NetcodeBootstrap.ClientWorld;
 NetcodeBootstrap.ClientWorlds.Clear();

 World world = new World("ClientWorld", source.Flags);

 DriverMigrationSystem migrationSystem = world.AddSystemManaged<DriverMigrationSystem>(new DriverMigrationSystem());

 var ticket = migrationSystem.StoreWorld(source);
 source.Dispose();

var newWorld = migrationSystem.LoadWorld(ticket, world);

 var systems = DefaultWorldInitialization.GetAllSystemTypeIndices(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.Presentation);
 NetcodeBootstrap.ClientWorlds.Add(world);

 DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, systems);
 ScriptBehaviourUpdateOrder.AppendWorldToCurrentPlayerLoop(world);

 setup.InitializeClientWorld(newWorld);
#

Meanwhile currently learning animation is not really there for entities and reconsidering my choices haha

sharp tartan
#

Gotcha, I would have used scenes for that instead of swapping worlds.
Yea. Animation, Audio, and UI are the big missing pieces for DOTS. You choices are either 3rd party assets like Rukhanka or have a hybrid system using Playables. Playables plays nicely with the Netcode prediction systems. But you're not gonna get 5000 of them playing smoothly.

vital ravine
# sharp tartan Gotcha, I would have used scenes for that instead of swapping worlds. Yea. Ani...

Thanks for the info.

The reason I swap worlds is really to work with my gamemode system, each of which have different systems running. Some systems share common tags/components like Death, Spawn, etc (so they could conflict with eachother if all systems were running at the same time) and not really for loading a different scene or map.

Originally I was just adding/removing systems manually, but I ran into some problems.

I checked the DriverMigrationSystem class, and it has this comment and thought sounds similar to what I want but not sure if its the exact use case (used along side with [DisableAutoCreation]

   /// <summary>
   /// A system that should be used to temporarly keep the internal transport connections alive while transferring then
   /// to another world.
   /// For example, you can rely on the DriverMigrationSystem to re-use the same connections in between a lobby world and the game world.
   /// </summary>

All of this can be due to me being new to the ECS package (and not really knowing the best way to handle these cases yet)
Is there a way to attach specific systems to specific unity scenes?

#

Or maybe is there a better way to handle this entire gamemode situation haha, I'm open to suggestions

sharp tartan
#

I'm not nearly familiar enough with DOTS to be giving suggestions. I've never worried about adding or removing systems. I've just been relying on RequireForUpdate to stop things from running.

The wizards over in #1062393052863414313 would have better opinions on swapping out worlds and/or systems