Best way to link MonoBehaviours to an Entity in 1.0?

After looking for it it in the documentation and scouring the forum, I wasn’t able to come up with a satisfying answer. Earlier versions of the Entities package had the concept of companion objects that would mirror the tranform of an entity and allow for attaching classic MonoBehaviours as component objects.

Previously I would use something like the following to attach arbitrary components to an entity.

public class HybridComponentConverter : MonoBehaviour, IConvertGameObjectToEntity
{
   [SerializeField]
   private List<Component> _componentList;

   public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
   {
      foreach (Component component in _componentList)
         conversionSystem.CreateAdditionalEntity(component);
   }
}

Seeing as the conversion API is being deprecated in favor of baking and and no longer works with the current subscene workflow, I’m not sure how to adapt my content properly.

I would like to able to to author my entity bakers and classic components alongside each other in the same hierarchy in the editor and have them be baked with a system that will not be deprecated upon the package leaving experimental status.

If anyone has experience with this in 1.0 and can link me any resource I would highly appreciate it.

There is no “best” way currently, as there are pro’s and con’s to each.

If you’re using subscenes, then bakers are the only option atm.

If you’re looking for more of a hybrid approach without subscenes and still relying on GameObjects, runtime authoring is always an option. Though, it won’t be as fast as full pure solution or subscenes. Take a peek at EntitiesExt, see if it suits the needs.

Class IComponentData that contain a game object prefab reference can be used. You just need a system that spawns the game object and stores a reference to the instantiated game object in a Class IComponentData.

1 Like