Skip to content

Make MonoBehaviour components accessible in the Bridge Layer

What

As the Bridge Layer is responsible for connecting the DOTS and Managed layers, it needs to have access to both of them, including MonoBehaviour components from the Managed Layer.

Why

To allow MonoBehaviour components from the Managed Layer to be accessible in the Bridge Layer.

How

Add a Stratkit.Entities.HybridBaker.ConvertGameObjectToEntity component to your GameObject along with a custom authoring component that inherits from AGameObjectToEntityAuthoring, e.g.:

    public sealed class ResourcesDialogHybridComponent : BaseHybridComponent { 
        // ...
    }

    [DisallowMultipleComponent]
    public sealed class ResourceDialogAuthoring : AGameObjectToEntityAuthoring {
        public override void ConvertToEcsComponent(Entity entity, EntityManager entityManager) {
            entityManager.AddComponentData(entity, GetComponent<ResourcesDialogHybridComponent>());
        }
    }
Now whenever the GameObject is added to the scene, their ECS counterpart will also be added to the world, allowing it to be accessed by both sides.