Search Unity

How to dynamically add hybrid/MonoBehaviour components?

Discussion in 'Entity Component System' started by gigamech, Mar 31, 2018.

  1. gigamech

    gigamech

    Joined:
    Mar 31, 2015
    Posts:
    23
    I've looked through the TwinStickShooter sample run through the `EntityManager` methods, and I can't figure out how to add `MonoBehaviour` components dynamically.

    The only way I can see is creating a gameObject with a `GameObjectEntity` component and then "importing" it all at once. That's fine if I never want to add or remove components at run-time, but that's missing out on half the fun of ECS's: super-dynamic objects. Am I missing something or is dynamic "hybrid" components just something that hasn't been implemented yet?
     
  2. FastTurtle222

    FastTurtle222

    Joined:
    Dec 24, 2017
    Posts:
    28
    Did you ever figure this out?
     
  3. gigamech

    gigamech

    Joined:
    Mar 31, 2015
    Posts:
    23
    No, sorry. I just abandoned the hybrid approach and went "pure" rolling my own systems for things that aren't accessible from ECS (e.g. Physics).
     
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,983
    and how do you handle skinned mesh animations?
     
  5. gigamech

    gigamech

    Joined:
    Mar 31, 2015
    Posts:
    23
    Easy. I don't ;) I'm not making anything substantial, just some little sketches to get used to the API and ECS style.
     
  6. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    For now you just add the MonoBehaviour component to the GameObject like we've always done using GameObject.AddComponent(), then use EntityManager.AddComponent() to add the new component to the entity system as well. See this post for more info.