Cannot alter mesh material color while preserving transparency
So, here's the deal: I've upgraded my project to URP, and all the old shaders I was using needed to be swapped to URP-compatible ones. Among the objects that needed new shaders were some animated plane meshes I imported that look like banners blowing in the wind. The only URP-compatible shader I could find that didn't produce horrible visual artifacts in the transparent portions of each mesh was Universal Render Pipeline > 2D > Sprite-Lit-Default.
Now, here's the problem: where once I could easily fade the banners in and out using code, I find myself no longer able to. Setting the meshrenderer's material color does nothing. I consulted some other questions like this, to which the answer was essentially use SetColor() with "_BaseColor" as the first parameter. Unfortunately, when I try this I get an error message saying Material doesn't have a color property '_BaseColor.'
I'm a bit lost. Is this a bug in Unity, or should I be doing something differently here? Here's the function that produces the above error, in case it's responsible somehow:
public void setAlpha ( float newAlpha ) {
Color materialColor = meshRenderer.material.GetColor(
"_BaseColor" ); materialColor.a = newAlpha; meshRenderer.material.SetColor( "_BaseColor" , materialColor ); }
Your answer
Follow this Question
Related Questions
URP - How to get rid of glossy terrain? 0 Answers
URP Shader Graph not working on Android 0 Answers
Overlay camera rendering over entire base camera 0 Answers
Universal renderer not working at all 0 Answers
Render inbetween two post processing effects in URP? 0 Answers