Search Unity

hybrid ecs, how to keep components on gameobjectentity when disabling/enabling the GameObject

Discussion in 'Entity Component System' started by kstothert, Jan 20, 2019.

  1. kstothert

    kstothert

    Joined:
    Dec 8, 2016
    Posts:
    68
    Code (CSharp):
    1. var go = some gameobject with gameobjectentity component
    2. // add ecs components to go
    3. go.SetActive(false);
    4.  
    5. go.SetActive(true);
    6. // missing the previously added ecs components
    I use this to manage hierarchical UI stuff but when i renable the gameobject the ecs components I has previously added are gone. Does the gameobjectentity destroy the entity and recreate it when active is toggled? If so why doesn't it add the disabled component to each gameobjectentitie in the hierarchy?
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Look at GOE source for understanding. Disable removes entity, Enable creates new entity with ICD/ISCD handled from ComponentDataWarpper on GO, and if you add components to Entity they of couse not adds to GOE.