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.

Question How to access ComponentData from Gameobject

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

  1. LDHTL


    May 24, 2020

    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());
    3. prefab.Count = (int) slider.value;
    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