Yo, I’ve created simple C# script which is using Decal Projector Component’s fade factor to fade out instantiated decal. Unfortunatelly this fading effect only works when I move the slider in the inspector but not when I modify projector.m_FadeFactor variable from script. Despite the fact that editor Fade Factor slider properly updates based on C# script, the opacity of decal itself will stay unchanged, even if the fade value is set to 0.
I also tried the following to dynamically chagne decal’s transparency but with no success:
Use projector’s material to set color alpha channel
Use projector’s material “Global Opacity” slider
Can somebody help me with this simple fading-out instantiated decals please?
Any help will be much appreciated.
Side Notes:
Projector is not instantiating its own material during runtime but rather uses sharedMaterial for some reason so coloring one decal will color the rest as well.
The m_FadeFactor variable is in range from 0 to 1 while inspector slider value goes from 0 to 100.
Indeed this is an API issue.
When something change in the Inspector, the OnValidate() method is called. It is a public function on DecalProjectorComponent that you need to call manually after a change to update the decal when scripting at the moment.
I’ll enter an issue on this. Hopefully this workarround will work for you.
For the next person who comes here, it’s fixed now when setting it through code but not when setting it through an animation. So add the following wonderfully confusing code to your object, which will fix it:
[ExecuteInEditMode]
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
[ExecuteInEditMode]
public class AnimatedDecal : MonoBehaviour
{
private DecalProjector _decalProjector;
void Awake()
{
_decalProjector = GetComponent<DecalProjector>();
}
void LateUpdate()
{
_decalProjector.fadeFactor = _decalProjector.fadeFactor;
}
}
Thanks for this. In addition I think instead of setting it as [ExecuteInEditMode], it should be [ExecuteAlways] based on what the documentation states.
Same problem. Will try to use provided hack. It’s too bad they dont provide the decal projector with an update EveryFrame setting etc like they do with other components