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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Hybrid ECS : Add component to existing entity

Discussion in 'Entity Component System' started by unity_VpxV03EStwvUzA, Sep 12, 2018.

  1. unity_VpxV03EStwvUzA

    unity_VpxV03EStwvUzA

    Joined:
    Apr 2, 2018
    Posts:
    3
    Hi there!

    I'm have a IncreaseHPSystem working with hybrid entities.

    When my stats increase, I want to increase my maximum HP.

    I thought I could do like Pure ECS :

    When my stats increase, add increaseHP component to my hybrid entities.

    My IncreaseHPSystem will then pick it up because it need increaseHP component in the structure.

    Then increase the MaxHP.

    Well it doesn't work.

    When I add a component to my game object, it doesn't add it to the entity during runtime.

    Is there a way to do it?

    Also, Should I just increase my HP via OOP and not use Hybrid ECS for that kind of thing? I love the ECS way of coding and try to use it for everything, but that might not be a good idea.

    Thank you!
     
  2. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    Why don't you make the IncreaseHP component a ComponentData instead and add that to the GameObjectEntity's entity? Move away from MonoBehaviours, hybrid makes that easy.
     
    unity_VpxV03EStwvUzA likes this.
  3. unity_VpxV03EStwvUzA

    unity_VpxV03EStwvUzA

    Joined:
    Apr 2, 2018
    Posts:
    3
    I still have issue knowing what Hybrid can do or not.

    If I want to add a componentData to my game object entity, how would I proceed? Do I need to use the entity manager like with Pure?
     
  4. unity_VpxV03EStwvUzA

    unity_VpxV03EStwvUzA

    Joined:
    Apr 2, 2018
    Posts:
    3
    God I should just read every post made by eizenhorn, that guy is a beast!
     
  5. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    :eek:
     
  6. NearAutomata

    NearAutomata

    Joined:
    May 23, 2018
    Posts:
    51
    In Hybrid ECS you'd leverage PostUpdateCommands in your non-jobified OnUpdate:
    Code (CSharp):
    1. PostUpdateCommands.RemoveComponent<FooComponent>(entity);