Hi, I kinda want my custom systems to run at a later point,
currently, I’m doing this by puting [DisableAutoCreation] on every of my custom systems,
but it feels inefficient and error-prone (I may forget to do so at some point)
I’m wondering if there could be a better way to ahieve this with a few function calls,
or is there a way to simply initialize the world with only default systems?
I have created a custom bootstrap code to only include unity systems at the beginning. You can add your own systems or have a loading logic for other systems that you wanted to add here. But on build i can’t seem to get it to work, unity adds all of the systems automatically when i am playing from a build so beware of that.
Also you need to add UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP or UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP_RUNTIME_WORLD to your scripting define symbols to make unity disable auto creations all together. So creating all of the systems you want falls on you
Edit : You may need to get a clean build for it to works. It suddenly started working for me when got a clean build going
Another Edit: I haven’t tested if your systems are inside global namespace, they may get ignored from systems namespace check, because they got included inside default unity namespace. Will check in a bit and update here
public class WorldBuilderCustomBootstrap : ICustomBootstrap
{
public bool Initialize(string defaultWorldName)
{
World world = new World(defaultWorldName);
World.DefaultGameObjectInjectionWorld = world;
NativeList<SystemTypeIndex> systemsToRemove = new NativeList<SystemTypeIndex>(Allocator.Temp);
NativeList<SystemTypeIndex> systems = DefaultWorldInitialization.GetAllSystemTypeIndices(WorldSystemFilterFlags.Default);
foreach (var system in systems)
{
var systemName = TypeManager.GetSystemName(system);
if (!systemName.Contains(new FixedString128Bytes("Unity")))
{
systemsToRemove.Add(system);
continue;
}
Debug.Log(system);
}
foreach (var systemToRemove in systemsToRemove)
{
int index = systems.IndexOf(systemToRemove);
systems.RemoveAtSwapBack(index);
}
var initializationSystemGroup = world.GetOrCreateSystemManaged<InitializationSystemGroup>();
var simulationSystemGroup = world.GetOrCreateSystemManaged<SimulationSystemGroup>();
var presentationSystemGroup = world.GetOrCreateSystemManaged<PresentationSystemGroup>();
DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, systems);
initializationSystemGroup.SortSystems();
simulationSystemGroup.SortSystems();
presentationSystemGroup.SortSystems();
ScriptBehaviourUpdateOrder.AppendWorldToCurrentPlayerLoop(world);
systemsToRemove.Dispose();
systems.Dispose();
return true;
}
}