#Use netcode for entities without using ClientServerBootstrap

1 messages · Page 1 of 1 (latest)

civic shard
#

after following the unity tutorials, I would like to manually decide when to connect to a server / host a server, but it appears the only advertised way is to use ClientServerBootstrap, I've tried manually using the methods in ClientServerBootstrap, like ClientServerBootstrap.CreateServerWorld("ServerWorld");, and ClientServerBootstrap.CreateClientWorld("ClientWorld");, but it doesn't appear to work, any suggestions?

vernal sail
#

Hey @civic shard , can you elaborate on what you mean when you say "it doesn't work"? What exactly does not work with this approach?

civic shard
vernal sail
#

Oh I see. I'd recommend reading this: https://docs.unity3d.com/Packages/com.unity.netcode@1.0/manual/networked-cube.html#establish-a-connection
By bypassing the Bootstrap, you don't have "autoconnection". Thus, you need to instruct the ServerWorld to listen on a specific port, and you need to instruct the ClientWorld to connect to said localhost server.
See ConfigureClientWorldSystem inside ClientServerBootstrap. You likely just need to set ClientServerBootstrap.AutoConnectPort = 7979; // You can choose this port value.

civic shard
# vernal sail Oh I see. I'd recommend reading this: https://docs.unity3d.com/Packages/com.unit...

unfortunately I don't know what I've done, but the unity editor now closes without warning, it appears to be caused by a stack overflow, what I've linked is a part of the massive log error, and this is my code for starting client/server without the clientbootstrap ```[Preserve]
public partial struct NetworkManagerSystem : ISystem
{
public void OnCreate(ref SystemState systemState)
{
ClientServerBootstrap.AutoConnectPort = 7979;

    StartServer(7879);

    StartClient("127.0.0.1", 7979);
}

public void StartClient(string ip, ushort port)
{
    ClientServerBootstrap.DefaultConnectAddress = NetworkEndpoint.Parse(ip, port);

    ClientServerBootstrap.CreateClientWorld("ClientWorld");
}

public void StartServer(ushort port)
{
    ClientServerBootstrap.DefaultListenAddress = NetworkEndpoint.Parse("127.0.0.1", port);

    ClientServerBootstrap.CreateServerWorld("ServerWorld");
}

}```

vernal sail
#

NetworkManagerSystem is likely erroneously added to netcode worlds too, so you're recursively spawning worlds. I.e. Every spawned world will create 2 more worlds.
Use the WorldSystemFilter attribute on the system.

civic shard
#

I just want to say I'm pretty new to DOTS, especially multiplayer, so i'm sorry if it's a hassle

deep mauve
#

first: you need prevent the ClientServerBootstrap Initialise method to be called, otherwise you are creating more world than expect).
So you need to write one that does not call this default (generally speaking).
Then, if you do that call in a NetworkManagerSystem, this MUST be called only a world that it is not either Client or Server world.
So you should add a

[WorldSystemFilter(WorldSystemFilterFlags.LocalSimulation)]

These methods actually actually create worlds. That may be causing some issue (and this is nice to know).

civic shard
civic shard
#

Alright, absolutely no idea how this worked, but I switched the system to a monobehaviour and replaced OnCreate with OnEnable and it worked, I also updated unity to the latest beta version

deep mauve
#

What your bootstrap code is doing? You still need to create an LocalSimulation for this to work if you a system.
You can use the helper function in the ClientServerBootstrap for that.

Otherwise just invoke the methods from a monobehavior and that it.

#

Ah you did!