ComponentType and inheritance

Heya, folks.

I’m trying to filter Entities with base class while derived class component is attached to entity.
Classes:

public class ObjectCactusStageSystem : ObjectStageSystem
public class ObjectStageSystem : MonoBehaviour

Filter:

 active_group_desc = new EntityQueryDesc
        {
            All = new ComponentType[] { typeof(DropStage), ComponentType.ReadOnly<ObjectStageSystem>() }
        };

But it doesn’t quite work.

When the base class is attached to entity it works perfectly.
Am I missing something dramatically? Is it possible to achieve?

Thanks.

ComponentType doesn’t take inheritance into account. You have to specify each derived type you’re looking for, or check for subtypes per-chunk.

I think they’re working on a solution for this as it’s been an issue dealing with Transform → RectTransform.

My solution was to have 2 queries, one for Transform, one for RectTransform, and then run Entities.ForEach per-query.

In my RectTransform foreach function I simply called the base Transform Version of the function.

1 Like

Hi, @recursive .

Thanks for the info. I’m dealing with it same way as you right now.

But as the count of derived types is growing system’s code is getting quite bulky.

The queries were designed to be efficient for Components (IComponentData) which can’t be derived (as they’re structs). However they do support querying classical MonoBehaviours (and other managed types) to provide support for a hybrid solution for existing projects allowing parts to be converted at a time and for engine components that Unity hasn’t build native Entity support for yet.

I’m curious, are you trying to develop a new project only using classic MonoBehaviours but with the Entities package? Or just trying to convert an existing solution to use Systems?

Project contains some moving pure ECS elements. And those elements performer changes on static GameObject elements.

For example, System queries for all entities bound to GameObject and fires method call in each ObjectStageSystem which results in some classic changes on the GameObject (like child switch on/off, animation triggers).