Greetings!
I use URP. I’m modifying my MeshRenderer Material instance in runtime via code, specifically it’s alpha channel. Problem: material renders much less transparent UNTIL I pause and modify it’s color’s transparency field in inspector, changing transparency by 1 (of 255). Then it becomes as transparent as expected… until next update via code.
BEFORE/AFTER manual fix in inspector:
And yes, turning it back from “5” (of 255) to “4” (as it was before manual fixing, meaning original set-by-code value) keeps it same transparent as after fix, meaning that once I modify alpha channel field in inspector, it starts rendering properly, but before that, when was set by code, it’s looking MUCH more opaque.
More context-based notices:
- In my process I’m lerping color from some basic transparency (lets say [10/255]) to zero [0/255]. This wrong rendering transparency (when I don’t modify it in inspector) actually does go to zero, corellating with values I set via code, but it becomes really transparent only near to end of lerp, being MUCH too opaque most of lerp period.
- Removing all semi-opaque or fully opaque objects behind this mesh (by disabling their GO’s) doen’t help.
- After broken code-based color update, when I’m modifying color in inspector, only update of A-channel fixes problem. Modification of R/G/B has no “magical fix” effect.
- (NOTICED AFTER POSTING) On image 2 (material window closeup), we can see color (bar) slighly differs in shade after manual update, despite RGB wasn’t modified, only A-channel.
More context:
- I use MeshRenderer, some of parents in hierarchy are Canvas/UI.
- I use next (image below) way of setting color:
radar_signatures[i].phantoms[j].meshRenderer.material.SetColor("_color", color);
It surely shots each update, and we are sure it’s proper color I want, because it shows correct value in the inspector. - In this example I use simple URP ShaderGraph, but also tried with default URP unlit (referring to “_BaseColor” instead of “_color” in code in such case) - no difference.
I have strong confidence in programming, intermediate confidense in basic use of shaders and materials except deep rendering mechanism part. I’ve spent many hours trying to solve this problem either find solution on the internet. I’m not sure if it is a bug, but it’s first time I notice something like this, plus I have my transparency value properly shown in inspector but not actually renderer. Asking for help.