Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

What the ComponentWrapper exactly does?

Discussion in 'Entity Component System' started by Sergey_Suslov, Apr 6, 2018.

  1. Sergey_Suslov

    Sergey_Suslov

    Joined:
    Nov 20, 2017
    Posts:
    12
    Do I understand correctly that WrapperComponent just used to create components for an Entity which created by GameObjectEntityComponent? And it's its only mission?

    And how do prefabs works with pure ECS?
    GameObjectEntityComponent.CreateEntity () calls multiple times? Or I should Instanciate GameObject with Wrappers and EntityComponent multiple times?
     
  2. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    Right now the WrapperComponent is simply used to wrap entity component data so it can be serialized and attached to a GameObject in the editor. This is useful when you're using the hybrid ECS approach (Entity and MonoBehaviour components together) or just want to construct entities in the editor instead of through code.

    Prefabs don't currently work with pure ECS. If you need / want to use a prefab or GameObject with ECS you have to attach a GameObjectEntity to it and WrapperComponents for any entity components it should have.

    It's kind of an awkward workflow, but it's only temporary. The goal is to eventually eliminate the need for any GameObjectEntity or WrapperComponent at all, and to have it all "just work" like good old game components do now.

    Read the last paragraph on this page for more info.
     
    Last edited: Apr 7, 2018
    jg4006 likes this.
  3. Sergey_Suslov

    Sergey_Suslov

    Joined:
    Nov 20, 2017
    Posts:
    12
    Thanks for response!
    One thing I still don't get, should wrapped components be serialized every update at runtime? It is not happening for me, maybe I'm doing something wrong. In "RotationExample" it is not happening too. So, i suppose they're only used to initialize entity components at begin?
    And in rare cases when you manually interact with gameoject and classic components?
     
  4. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    Correct. Wrapped components are only used for initialization. Once you enter play mode it's all handled by the entity system itself. So you can only make changes to entity component values through code at run-time. You can only observe them in real-time through the editor using the Entity Debugger. This is again a limitation of the current implementation.

    The GameObject and all it's classic components are automatically registered with the entity system during run-time initialization when a GameObjectEntity component is attached. However, if you want to add/remove any classic components during run-time then you need to add/remove them manually yourself. See this post for info on how to do that.
     
    Last edited: Apr 7, 2018