Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to access ComponentData from Gameobject

Discussion in 'Entity Component System' started by LDHTL, Jan 8, 2023.

  1. LDHTL

    LDHTL

    Joined:
    May 24, 2020
    Posts:
    2
    Hi,

    I have a question about how to change data from a component of an entity in an Gameobject.

    Currently I am accessing data like:
    Code (CSharp):
    1. var prefab = _entityManager.GetComponentData<PrefabComponent>(GetPrefabEntity());
    2. slider.value = prefab.Count;

    But when I try to change the Component:
    Code (CSharp):
    1. var prefab = _entityManager.GetComponentData<PrefabComponent>(GetPrefabEntity());
    2.  
    3. prefab.Count = (int) slider.value;
    4.  
    5. _entityManager.SetComponentData(GetPrefabEntity(), prefab);

    Nothing happens. The Inspector in authoring mode does work and not change. The Inspector in runtime mode changes according to the values, but the rendered display does not change at all.

    Does anyone knows what the problem is?
    Thanks in advance