Hello, I have a simple Agent prefab meant to move in the scene. That agent has a Capsule child with a MeshRenderer. The agent is then spawned as an entity and the MeshRenderer is converted as a RenderMeshArray.
I would like to access the Capsule child at runtime and change that material’s color. I have tried accessing it through the agent entity’s Child Buffer to retrieve the Capsule entity, but Unity throws me an error saying the entity doesn’t have a Child buffer :
var agentEntity = EntityManager.Instantiate(spawnerAspect.AgentPrefab);
Random r = new Random((uint)(1));
float rand = r.NextFloat();
var child = SystemAPI.GetBuffer<Child>(agentEntity)[0].Value;
SystemAPI.SetComponent(child, new HDRPMaterialPropertyBaseColor
{
Value = rand < profile.GenderRatio ? this.ColorToF4(UnityEngine.Color.blue) : this.ColorToF4(UnityEngine.Color.magenta)
});
While the Child BufferComponentData has clearly been added to the agent entity :
Any help to access the child entity would be appreciated. Thank you for your time.