Why is that so obscure? The documentation is impossible to find. Only outdated posts from 2018.
I create custom world with new. I create systems with CreateSystem(); Then update never happens wen I run world.Update(); and none of the systems show up in entity debugger.
No google search gives any useful information. Please help.
Started to find bits and pieces of code. Mostly associated with ICustomBootstrap. Ended up with this code:
public class WorldCreator : MonoBehaviour
{
World World;
void Start()
{
World = CreateSimulationWorld("BattleSimulationWorld");
}
public World CreateSimulationWorld(string name)
{
IReadOnlyList<Type> systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);
List<Type> simulationSystems = new List<Type>();
for (int i = 0; i < systems.Count; i++)
{
if (systems[i].Namespace != null && (systems[i].Namespace.Contains("UnityS") || systems[i].Namespace.Contains("BattleSimulation")))
{
simulationSystems.Add(systems[i]);
}
}
Debug.Log(simulationSystems.Count);
var world = new World(name, WorldFlags.Live & WorldFlags.Simulation);
DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, simulationSystems);
ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
var simulationGroup = world.GetOrCreateSystem<SimulationSystemGroup>();
return world;
}
void Update()
{
World.Update();
}
}
It finds 20 systems. Two of them are my custom systems, the rest are a modified unity physics and transforms systems.
I can see my two, but not the other ones.
Edit: Silly me, the transform systems were nt showing because of Show Inactive was false, now true. But the physics systems are not showing up…
All systems that I add are there I checked. But none of the physics systems show up in the debugger. I think I can still work with that, but would be good to see them.
ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
Adds the systems into the update loop in a way that makes them visible in entity debugger. However I didn’t realize that it causes them to actually automatically update. So I will have to remove that.
So now I’m back to not knowing how to show my systems in the debugger. Not a huge deal, but I’d love to know how to see them there without making them a part of the loop.
Is there a reason you don’t want to use the ICustomBootstrap to initialise your custom world? Doing so has worked perfectly for me, with systems properly being added and the world (and systems) being properly shown in the entity debugger.
I found the documentation on ICustomBootstrap still a bit fuzzy, but if you would want to go down that road, I and others here could probably help you.
1: ICustomBootstrap does not allow easy manual updating / easy network synchronization. You have to update from a monobehaviour.
2: ICustomBootstrap happens when the game first starts. If you have a loading menu scene etc. It will happen then rather then in the true game. So ICustomBootstrap kind of breaks mult-scene games.
I don’t understand this at all? What does a monobehaviour have to do with ICustomBootstrap
What you should be doing is setting up your default world in the custom bootstrap while caching the list of systems you need for each other world that you can create at later points (look at netcode for example.)
The trick is actually to only have 1 world in the update loop with all other worlds updates called from the default world groups.
This is how netcode works and if you look at it’s bootstrap, when it creates the server/client worlds it gets the core groups in the server/client worlds then adds them to the base groups in the default world.
// server world
var initializationGroup = world.GetOrCreateSystem<ServerInitializationSystemGroup>();
var simulationGroup = world.GetOrCreateSystem<ServerSimulationSystemGroup>();
//Pre-create also all the necessary tick systems in the DefaultWorld
var initializationTickSystem = defaultWorld.GetOrCreateSystem<TickServerInitializationSystem>();
var simulationTickSystem = defaultWorld.GetOrCreateSystem<TickServerSimulationSystem>();
//Bind main world group to tick systems (DefaultWorld tick the client world)
initializationGroup.ParentTickSystem = initializationTickSystem;
initializationTickSystem.AddSystemToUpdateList(initializationGroup);
simulationGroup.ParentTickSystem = simulationTickSystem;
simulationTickSystem.AddSystemToUpdateList(simulationGroup);
// client world
var initializationGroup = world.GetOrCreateSystem<ClientInitializationSystemGroup>();
var simulationGroup = world.GetOrCreateSystem<ClientSimulationSystemGroup>();
var presentationGroup = world.GetOrCreateSystem<ClientPresentationSystemGroup>();
//Pre-create also all the necessary tick systems in the DefaultWorld
var initializationTickSystem = defaultWorld.GetOrCreateSystem<TickClientInitializationSystem>();
var simulationTickSystem = defaultWorld.GetOrCreateSystem<TickClientSimulationSystem>();
var presentationTickSystem = defaultWorld.GetOrCreateSystem<TickClientPresentationSystem>();
//Bind main world group to tick systems (DefaultWorld tick the client world)
initializationGroup.ParentTickSystem = initializationTickSystem;
initializationTickSystem.AddSystemToUpdateList(initializationGroup);
simulationGroup.ParentTickSystem = simulationTickSystem;
simulationTickSystem.AddSystemToUpdateList(simulationGroup);
presentationGroup.ParentTickSystem = presentationTickSystem;
presentationTickSystem.AddSystemToUpdateList(presentationGroup);
And that’s how you get them to show up in the entity debugger
I create a two new worlds with Start() update them with Update() and Dispose with OnDestroy(). Works really well. I can still reload the loading menu scene and get fresh worlds.
Unity’s netcode is very different from how my networking works. I have lock-step hybrid using a low level transport layer. I really not sure why I would want a list of systems I am reusing worlds using CopyAndReplaceEntitiesFrom. I don’t have a client / server I have a delayed deterministic lock step world and a predictive world both running on each computer. I still have a reconciliation server but only to compile inputs and that is in monobehaviour land with fixed point math.
Since I need to control when, how and how often the the “main” lock step world is updated and when to roll back the predictive world “the world you see” and resimulate calling updated using a monobehaviour is critical. All of my prefab entities also live in the same monobehaviour.
Remember DefaultWorldInitialization.GetAllSystems will get you all systems that are not tagged with [DisableAutoCreation]
It would be nice to have a working entity debugger but I have found it not to be need.
So it really depends on the project you’re making when deciding for ICustomBootstrap or another custom solution (like your manual MonoBehaviour). If the requirements of your project don’t exclude ICustomBootstrap workflow, I would recommend using it so you can see your world and systems in the Entity Debugger.