Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Best way to link MonoBehaviours to an Entity in 1.0?

Discussion in 'Entity Component System' started by Ryunis, Oct 14, 2022.

  1. Ryunis

    Ryunis

    Joined:
    Dec 23, 2014
    Posts:
    24
    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.
    Code (CSharp):
    1. public class HybridComponentConverter : MonoBehaviour, IConvertGameObjectToEntity
    2. {
    3.    [SerializeField]
    4.    private List<Component> _componentList;
    5.  
    6.    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    7.    {
    8.       foreach (Component component in _componentList)
    9.          conversionSystem.CreateAdditionalEntity(component);
    10.    }
    11. }
    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.
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    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.
     
  3. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    258
    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.
     
    Deleted User likes this.