I'm building a prototype using spline the generate a Mesh for a conveyor belt there is actually 2 spline mesh ( the frame mesh & the flat belt mesh) .
The player need to select a point, a mesh is created with a spline.
From now on, the player can move it's mouse and a system generate a preview of the mesh with a "ghost , valid or invalid" material depending of the position, the mesh regenerate each time the end point move.
My question is, after spawning the entity :
Entity mainConveyorBeltEntity = state.EntityManager.Instantiate(ConveyorBeltPrefab);
state.EntityManager.SetName(mainConveyorBeltEntity, "mainConveyorBeltEntity");
Entity mainConveyorFrameEntity = state.EntityManager.Instantiate(ConveyorFramePrefab);
state.EntityManager.SetName(mainConveyorFrameEntity, "mainConveyorFrameEntity");
To modify in real time the mesh of both is this :
RenderMeshArray ConveyorBeltArray = state.EntityManager.GetSharedComponentManaged<RenderMeshArray>(mainConveyorBeltEntity);
RenderMeshArray ConveyorFrameArray = state.EntityManager.GetSharedComponentManaged<RenderMeshArray>(mainConveyorFrameEntity);
ConveyorBeltArray.Meshes[0] = UConveyorMesh.GenerateJob(); // this return a Mesh
ConveyorFrameArray.Meshes[0] = UConveyorMesh.GenerateJob(); // this return a Mesh
And to modify the material in real time :
if(isValidPlacement)
{
ConveyorBeltArray.Materials[0] = GhostValidMaterial;
ConveyorFrameArray.Materials[0] = GhostValidMaterial;
}
else
{
ConveyorBeltArray.Materials[0] = GhostInValidMaterial;
ConveyorFrameArray.Materials[0] = GhostInValidMaterial;
}
And finally applying it to the Entity :
state.EntityManager.SetSharedComponentManaged(mainConveyorBeltEntity, ConveyorBeltArray);
state.EntityManager.SetSharedComponentManaged(mainConveyorFrameEntity, ConveyorFrameArray);
The main point being that in the end the player is going to have a crapload of belts around in the prototype. So i'm trying to do it the right way.