#Changing material on renderer (Entities Graphics)

1 messages · Page 1 of 1 (latest)

clever frigate
#

So I have an Entity with various components generated from a GameObject. The gameObject this generates from has a MeshRenderer and a Mesh Filter (image 1). Traditionally, what I would do is now add my materials (its 2 I want in this case) to the Materials list of the Mesh Renderer, and then remove it again when I want my effect to disappear. How can I achieve the same effect with the entity now? My current approach looks like this:

RenderMeshArray renderMeshArray = entityManager.GetSharedComponentManaged<RenderMeshArray>(currentEntity);

List<UnityObjectRef<Material>> mats = new List<UnityObjectRef<Material>>(renderMeshArray.MaterialReferences); // First get the list of the already existing materials as my intended effect adds upon it, and doesnt replace it.
foreach(Material material in GameManager.Instance.outlineMaterials) // Add each required material from some reference somewehere
{
    mats.Add(material);
}

renderMeshArray.MaterialReferences = mats.ToArray();
ecb.SetSharedComponentManaged(currentEntity, renderMeshArray); // Set it back on the entity

This doesnt really work as after setting it it just set null (making it invisible due to even the original material and even the mesh being all overwritten with null). I think Im probably approaching this completely wrong and would like to know how it is done properly

formal geode
clever frigate
#

Im not sure I understand so you say I add the materials to when its still a GameObject (all of the ones I may ever need on it) and then activate/deactivate them?

formal geode
formal geode
clever frigate
#

For my needs all my materials are accessible in the editor so that should be fine but I think I still dont get how its actually done

formal geode
clever frigate
formal geode
#

The problem is the order of baking. During baking you don't know the order of execution of bakers and thus if you change some other baker parameter it can happen before or after the other baker will run

#

And RenderMeshArray will not be valid because it is created using Unity's own baking system

clever frigate
#

Well, applying the material directly to the mesh just showed me that my shader doesnt even work in DOTS

formal geode
#

Probably just some HybridInstanced flags, if the shader is not hand written

clever frigate
#

Im using one from the asset store I didnt even know DOTS needed special shaders I thought it was URP compatible till now

#

Yeah this is my breaking point man I have no idea about shaders and just tried implementing this with a technology I never used before for hours :(

formal geode
#

Unfortunately, I am unable to help you with a shader as I myself am not a shader guru. Regular ShaderGraph shaders are compatible by default while writing your own shaders is really hard for Entity Graphics

tardy dragon
strange cliff
#

I do recommend just playing around with shadergraph shaders though

rugged comet