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 change just that color?
[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();
}
}
I already tried a lot of stuff, creating more than one ComponentData instead of that one carrying the color, reviewing my algorithm, etc. etc. The whole point is that renderMeshArray, materialMeshInfo and material are shared among all entities of the same kind. In simple UnityEngine I can do this. Is there a way to overcome this in ECS?
MGodoy BR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.