Search Unity

Question Change NetworkDriver after Client and Server world creation?

Discussion in 'NetCode for ECS' started by joshrs926, Oct 16, 2023.

  1. joshrs926

    joshrs926

    Joined:
    Jan 31, 2021
    Posts:
    115
    I'm using Relay with Netcode for Entities and I'm creating a new INetworkStreamDriverConstructor to assign to
    NetworkStreamReceiveSystem.DriverConstructor before manually creating my client and server worlds. I assume I need to do it this way because you need the Relay Allocations in order to create RelaySeverData before doing all of the above. But I'd like to just let the default ClientServerBootstrap create the client and server worlds initially. But it appears that NetworkStreamReceiveSystem.OnCreate does work to create NetworkDriverStores and such as soon as the world is created. Can I go back after the fact and re-setup the NetworkDrivers for an existing client or server world once I get the Relay allocations and then call Connect and Listen to the endpoints? Or is it the case that NetworkDrivers need to be set up properly at world creation?
     
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    895
    At the moment we don't allow re-cratinging the Driver after the worlds has been created.
    The only proper way to implement this today is to implement a custom bootstrap that does create the worlds and instead, first get the relay up and running (and retrieve the server data) and then create the world using the provided
    RelayDriverConstructor.

    It is far from ideal though.
     
  3. joshrs926

    joshrs926

    Joined:
    Jan 31, 2021
    Posts:
    115
    Thanks for the info. That is what I’m currently doing so I’ll stick with that.