Hi. I am very new to ECS and I don’t know how to choose a specific component(or even if it is possible).
Let’s say I have DataX which implements IComponetData, and also have SystemA and SystemB which are componet systems (ex. SystemA inherits from ComponentSystem) and both of them use only DataX on their OnUpdate(). Is it possible to make only SystemA work in my scene?
An idea I came up with is to use a “tag” component which actually contains no data, as MoveUp struct used in FluentQuery scene in the official samples. But I don’t think it is a good practice to make a tag component every time I make a system. Any other good way?
Another way is to declare a single shared component data containing an int value and use EntityQuery.SetFilter for each of your systems. Just make sure to use a different int value in your shared component data for each system.
query.SetFilter(new SystemIndex { Value = 0 });
Do your know Is faster when?
OnUpdate(){ …
if (SystemIndex.val != 0) return; }
Or its only syntax sugar?
Thanks for your replying. Your idea is simpler and looks easy to implement. But is there no way to choose a specific component without adding new component data or without editing both system, like choosing a system from a MovoBehaviour class which manages entities?
What I was trying to do is that I made a very simple system which just counts up a number which is provided by a component data, using Entities.ForEach, and next because I want to make it work parallelly, I made another system which inherits from JobComponentSystem, but then I noticed I could not choose which to work.(Both systems worked at the same time although I wanted only new job system to work.)
It is ok to add a new component data and edit both systems to my project because they are very simple, if they are complex, that might be a problem. For example, when I want to make a system to debug another complex system, I need to make extra component data and edit the complex system too just for debug…
I found putting [DisableAutoCreation] attribute on a system might also be useful. Then do something like this.
var world = World.Active;
var simulationSystemGroup = world.GetOrCreateSystem<SimulationSystemGroup>();
var countSystem = world.GetOrCreateSystem<CountSystem>();
var rangeSystem = world.GetOrCreateSystem<RangeSystem>();
simulationSystemGroup.AddSystemToUpdateList(countSystem);
simulationSystemGroup.AddSystemToUpdateList(rangeSystem);
simulationSystemGroup.SortSystemUpdateList();
ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);