Hello! I am currently porting a terrain system to ECS and am having difficulty replicating GameObject MeshRenderer functionality inside of an ECS RenderMesh
The main issue is that MeshRenderer has a .materials array whereas RenderMesh seems to only support a single list. Background below – to clarify, I am attempting to overlay two materials on the same mesh with transparency. I am not trying to apply a different material to each of multiple submeshes.
Background: The terrain system I have consists of a few dozen 3D tile prefabs – e.g. curved segments of terrain, not cubes. At runtime, I read in a terrain file (from a server, can’t be assembled statically) containing a grid of tile types. For each tile, I select corresponding mesh and apply a single terrain material (UV mapped to a sprite sheet). Later on, I use mesh.CombineMeshes to process the grid of terrain tiles into 16x16 chunks.
So far so good. The issue arises when I need to apply a second material to the terrain. I have a feature that allows users to toggle various environment overlays. These use a custom shader to render another texture on top of the terrain with transparency. I’ve attached an image below. I have no idea how to replicate this effect using an Entity instead of a GameObject to represent each chunk, as there seems to be no way to apply multiple materials.
If you look at how the conversion system does it, it simply creates 1 entity per material with a shared parent. Pretty much what you should do as well.
Thanks for your reply! Mind elaborating a bit? If I have two entities each with their own RenderMesh (material + mesh), won’t I just get two overlapping meshes with different materials, render glitching which is on top depending on numerical precision? How do I parent two materials to the same mesh?