IL2CPP No server world in build

in il2cpp, there is no server world created
ie. calling this

for (int i = 0; i < World.All.Count; i++) {
    var world = World.All[i];
    if (world.GetExistingSystem<ServerSimulationSystemGroup>() != null) {
        return world;
    }
}

Debug.LogError($"no server world, count: {World.All.Count}");
return null;

cannot find the world. (called from a monobehaviour start method)
no other error is given or reason as to why it fail to initialize
not sure what to do or how to debug the problem

There is a bug in netcode 0.6 where the bootstrap can be stripped in some build configurations because it is missing the Preserve attribute. Not sure if that is causing this specific issue, but if it is you should be able to work around it by adding something like this to your project

[UnityEngine.Scripting.Preserve]
public class MyCustomNetCodeBootstrap : ClientServerBootstrap
{
    public override bool Initialize(string defaultWorldName)
    {
        return base.Initialize(defaultWorldName);
    }
}

Or just add that preserve attribute to your existing custom bootstrap instead if you have one.

1 Like