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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved How can I set color of a specific entity?

Discussion in 'Graphics for ECS' started by s-saens, Jul 2, 2023.

  1. s-saens

    s-saens

    Joined:
    Aug 14, 2019
    Posts:
    8
    I've tried to make it by instantiating a new Material object by doing like below:


    foreach(Entity entity in myEntityQuery)
    {
    var originalRMA = EntityManager.GetSharedComponentManaged<RenderMeshArray>(entity);

    if(originalRMA.Material == null)
    {
    Debug.Log("Material is null!");
    return;
    }

    Debug.Log("Set!");
    var newMaterial = new Material(originalRMA.Materials[0]);
    newMaterial.color = myColor;

    ecb.SetSharedComponentManaged(entity, new RenderMeshArray {
    Materials = new Material[] { newMaterial },
    Meshes = originalRMA.Meshes
    });
    }


    my code produces no compile error, but if I run it, it logs "Set!" at first for all of my entities which are being queried as myEntityQuery in the script above, but after that, it logs "Material is null!" every frame.
     
  2. Rukhanka

    Rukhanka

    Joined:
    Dec 14, 2022
    Posts:
    179
    s-saens likes this.
  3. s-saens

    s-saens

    Joined:
    Aug 14, 2019
    Posts:
    8