I have a method which iterates over all mesh renderers and their materials. I change color on the material named “Bodypaint (Instance)”. After accessing the material arrays the materials will not render properly and I have this strange effect where the background material/texture bleeds into the material of the moving object seen in the screenshot.
The material shader is HDRP/Lit.
Why does this occur? So far I’ve tried to establish if it has something to do with the material/shader render queue or if any of the material properties have changed. But, I’ve come up with nothing.
However, when pausing the editor in runtime the materials render just fine. I’ve also noticed that changing one of the attributes on the material shader, while paused, will solve the bleeding issue.
private static void SetBodyPaintMaterial(
Vehicle vehicle,
Rigidbody instanceBody)
{
MeshRenderer[] meshRenderers = instanceBody
.GetComponentsInChildren<MeshRenderer>();
foreach (var mesh in meshRenderers)
{
//TODO: Can we get this working?
List<Material> materials = new List<Material>();
mesh.GetMaterials(materials);
if (materials == null || materials.Count == 0 || materials[0] == null) continue;
foreach (var mat in materials)
{
if (mat.name.Equals("Bodypaint (Instance)"))
{
//Set the main Color of the Material to vehicles paintjob color
mat.SetColor("_BaseColor", vehicle.Paintjob);
}
}
}
}
My solution was to revert to older installation of unity (2021.3.11) and an older version of HDRP (v.12.1.7). The issue was probably with HDRP version 12.1.10.