Hi all,
I am implementing a basebuilding game (URP). Naturally, you can place stuff like walls, objects, and so on. Then a character moves to the position and builds the object. After the build process, the object persists in the world.
To achive this visually I have my entity show a mesh of the object with a shader that shows some kind of hologram instead of the real object. During the build process, I want to show the final mesh that appears out of thin air with a nice effect. And finally, the entity just shows the object.
Right now I have a PreFab of every final object. I also have one material with the holographic shader and one material with the constructing shader.
To change the materials of the entity I do something like this:
Entities.WithStructuralChanges().
ForEach((Entity ent, MaterialChangerData changer, in RenderMesh mesh) => {
RenderMesh modifiedMesh = mesh;
modifiedMesh.material = changer.changeToMaterial;
entityManager.RemoveComponent<MaterialChangerData>(ent);
entityManager.SetSharedComponentData<RenderMesh>(ent, modifiedMesh);
}).Run();
This has some drawbacks, for example, the BaseMap and NormalMap of the original material do not carry over to the new one and I did not (yet) figure out to copy it over.
Is this the right way to do it at all?
If there is another way, if so, what is it?
Any help is greatly appreciated.
Cheers
Reinhard