So I have an Entity with various components generated from a GameObject. The gameObject this generates from has a MeshRenderer and a Mesh Filter (image 1). Traditionally, what I would do is now add my materials (its 2 I want in this case) to the Materials list of the Mesh Renderer, and then remove it again when I want my effect to disappear. How can I achieve the same effect with the entity now? My current approach looks like this:
RenderMeshArray renderMeshArray = entityManager.GetSharedComponentManaged<RenderMeshArray>(currentEntity);
List<UnityObjectRef<Material>> mats = new List<UnityObjectRef<Material>>(renderMeshArray.MaterialReferences); // First get the list of the already existing materials as my intended effect adds upon it, and doesnt replace it.
foreach(Material material in GameManager.Instance.outlineMaterials) // Add each required material from some reference somewehere
{
mats.Add(material);
}
renderMeshArray.MaterialReferences = mats.ToArray();
ecb.SetSharedComponentManaged(currentEntity, renderMeshArray); // Set it back on the entity
This doesnt really work as after setting it it just set null (making it invisible due to even the original material and even the mesh being all overwritten with null). I think Im probably approaching this completely wrong and would like to know how it is done properly