I’m pretty new to ECS and most of the example systems I see work on one type of entity defined by a single archetype. Is it bad practice for a system to work with two distinct sets of entities.
What functions cover this and is it normal behaviour? (Maybe code examples I’ve seen are a little dated)
Aye thanks. I see that as the danger, if you let it get out of hand. Are there any official examples I can reference that use two multiple groups in a system?
Not sure about specific examples, but you can always look at the source of systems that Unity has developed. For example the ParentSystem uses 4 queries
protected override void OnCreate()
{
m_NewParentsGroup = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[]
{
ComponentType.ReadOnly<Parent>(),
ComponentType.ReadOnly<LocalToWorld>(),
ComponentType.ReadOnly<LocalToParent>()
},
None = new ComponentType[]
{
typeof(PreviousParent)
},
Options = EntityQueryOptions.FilterWriteGroup
});
m_RemovedParentsGroup = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[]
{
typeof(PreviousParent)
},
None = new ComponentType[]
{
typeof(Parent)
},
Options = EntityQueryOptions.FilterWriteGroup
});
m_ExistingParentsGroup = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[]
{
ComponentType.ReadOnly<Parent>(),
ComponentType.ReadOnly<LocalToWorld>(),
ComponentType.ReadOnly<LocalToParent>(),
typeof(PreviousParent)
},
Options = EntityQueryOptions.FilterWriteGroup
});
m_DeletedParentsGroup = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[]
{
typeof(Child)
},
None = new ComponentType[]
{
typeof(LocalToWorld)
},
Options = EntityQueryOptions.FilterWriteGroup
});
}