Hi, so I have a UI Dissolve shader im using as a fade in and out on a UI image. This works normally in one scene, but when trying to use it in other scenes it doesn't work, and then when coming back to the same scene where it was working after going to a bad scene, it no longer works. I can see the material updating in the inspector but this is not reflected in game. On restarting unity to the scene where the shader was working, it works again before a scene switch.
Heres my UI image dissolve handler script that I put on the image:
public class UIDissolveHandler : MonoBehaviour
{
private Image img;
private bool inScript = false;
private float dissolveAmount;
[SerializeField] bool test = false;
void Start()
{
img = GetComponentImage may be NSFW.
Clik here to view.
();
//Fade in on awake
DissolveOut();
}
public void DissolveOut()
{
StartCoroutine(StartDissolveOut());
}
public void DissolveIn()
{
StartCoroutine(StartDissolveIn());
}
IEnumerator StartDissolveOut()
{
inScript = true;
dissolveAmount = 0f;
img.materialForRendering.SetFloat("_Dissolve", dissolveAmount);
yield return new WaitForSeconds(0.75f);
while ((dissolveAmount < 1f) && (inScript == true))
{
dissolveAmount = Mathf.Clamp01((dissolveAmount + Time.deltaTime));
img.materialForRendering.SetFloat("_Dissolve", dissolveAmount);
yield return new WaitForEndOfFrame();
yield return new WaitForSeconds(0.005f);
Debug.Log(dissolveAmount);
}
inScript = false;
}
IEnumerator StartDissolveIn()
{
inScript = true;
dissolveAmount = 1f;
img.materialForRendering.SetFloat("_Dissolve", dissolveAmount);
while ((dissolveAmount > 0f) && (inScript == true))
{
dissolveAmount = Mathf.Clamp01(dissolveAmount + -Time.deltaTime);
img.materialForRendering.SetFloat("_Dissolve", dissolveAmount);
yield return new WaitForEndOfFrame();
}
inScript = false;
}
private void Update()
{
if (test)
{
dissolveAmount = Mathf.PingPong(Time.time, 1.0f);
img.materialForRendering.SetFloat("_Dissolve", dissolveAmount);
}
}
}
Heres my shader graph i use on the material i set the image to:
![alt text][1]
[1]: /storage/temp/207208-screenshot-2023-05-13-174403.png
Clik here to view.