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?
#Use netcode for entities without using ClientServerBootstrap
1 messages · Page 1 of 1 (latest)
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?
Well, when I use the ClientBoostStrap method, it creates a network entity and connects to the server, but nothing appears to happen when I try to manually call the methods in clientbootstrap from a monobehavior.
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.
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");
}
}```
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.
Hi, I've tried all the flags in WorldSystemFilter, and it looks like the only one that doesn't cause a stack overflow issue is ProcessAfterLoad, but that appears to be because it never calls the OnCreate method (at least in the editor)
I just want to say I'm pretty new to DOTS, especially multiplayer, so i'm sorry if it's a hassle
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).
good news, it no longer crashes, but bad news, it looks like the system is never initialized? I can't find it in the Entities Hierchy, and the debug statements I put in OnCreate are never shown in the console
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