Hi there, I use Unity for a long time, but I’m new to ECS.
I have created a SystemBase to change the color of some entities spawned but not all of them. I want to highlight a sub set of my entities.
I created this SystemBase. It changes the color, but of all of entities that shares the same material. Is there a way to create a new temporary material just for a single entity and reassign to it in order to chante just that color?
Thanks at advance. Here is my code:
[UpdateAfter(typeof(CityStageSpawnSystem))]
public partial class ApplyColorSystem : SystemBase
{
protected override void OnCreate()
{
}
protected override void OnUpdate()
{
Entities.ForEach((ref Entity entity, in ChangeColorComponent colorComponent, in RenderMeshArray renderMeshArray, in MaterialMeshInfo materialMeshInfo) =>
{
if(colorComponent.changeIt) {
var material = renderMeshArray.GetMaterial(materialMeshInfo);
material.color = new UnityEngine.Color(colorComponent.NewColor.x, colorComponent.NewColor.y, colorComponent.NewColor.z, colorComponent.NewColor.w);
}
})
.WithoutBurst().Run();
}
}