Combining Hybrid ECS and pure ECS

Is there a way to combine those two concepts to take advantage of the jobs systems, reactivity and other pure ECS features while still settling for regular animation, pathfinding, sprites etc. How would one implement that?

Not sure what you mean by “combining” but they can certainly co-exist. We have parts that are hybrid and parts that are pure.

That’s good to know. I guess my question is how to treat an entity as the hybrid type (accessing MonoBehavior components like Animation Controller) while managing it’s transform via pure ECS

Technically all examples I have seen are:

MonoBehaviour > ECS
At one point in your game loop copy the data to ECS world, during a system run your calculation, at the end copy it back

ECS > MonoBehaviour
Pick a point in your timeline and copy the data out.

If you look at anything “Authoring” in the ECS examples you can see this very well. The interaction is always “Modify MB” > “Copy the data over” > “Copy the data back”.

Add a Component that stores the GameObject reference to a Entity to access GameObject form a Entity
Add a Monobehaviour that stores the Entity to the GameObject to access the Entity from a GameObject

public class GameObjectToEntity : MonoBehaviour {
    public Entity Entity;
    private void Start() {
        EntityManager em = World.Active.EntityManager;
        Entity = em.CreateEntity();
        em.AddComponentObject(Entity, new EntityToGameObject(gameObject));
    }
}

public class EntityToGameObject : Component {
    public GameObject GameObject;

    public EntityToGameObject(GameObject GameObject) {
        this.GameObject = GameObject;
    }
}
2 Likes

That’s clever.

AFAIK, you can only add components deriving from IComponentData to an Entity, and they can only hold value types. Not sure how you could reference a GameObject from there?

You can attach anything to an Entity with AddComponentObject

2 Likes