- Home /
2D Image Sprite Not Fading In Standalone Build
In my recent 2D game, I wanted to fade certain scenes in and out. This is done by putting a black image overlay on top of everything in the scene and adjusting the transparency at appropriate times. Everything works perfectly in the editor. However, when I make a standalone build, the fade does not work properly. Instead, when fading the scene in (i.e. fading the black overlay from opaque to transparent), the overlay remains solid opaque black for the entire fade duration, then snaps to transparent at the end time at which it should have faded to transparent.
So far, while looking into the issue, I've seen people mention that this may be due to Unity needing you to specifically indicate you want to load certain textures in the standalone build through project settings. However, I can't seem to find how to do this for a 2D game with images.
Here is the inspector window for the relevant overlay:
And here are some parts of the script that may be relevant:
public class FadeInFromBlack : MonoBehaviour
{
private GameObject fadeFromBlackOverlay;
private void Awake()
{
fadeFromBlackOverlay = this.gameObject;
}
// Start is called before the first frame update
void Start()
{
//check to make sure we attached this to an image object
if (fadeFromBlackOverlay.GetComponent<Image>() == null)
{
Debug.Log("No image component found on fadeFromBlackOverlay");
return;
}
else
{
//set the black overlay to alpha 1 as we have it at alpha 0 right now; we left it at alpha 0 so that we can see the actual scene when we're working on it, but we need to start at full black overlay to "fade in"
Color fadeFromBlackOverlayColor = fadeFromBlackOverlay.GetComponent<Image>().color;
fadeFromBlackOverlayColor = new Color(fadeFromBlackOverlayColor.r, fadeFromBlackOverlayColor.g, fadeFromBlackOverlayColor.b, 1f);
fadeFromBlackOverlay.GetComponent<Image>().color = fadeFromBlackOverlayColor;
}
//now we're ready to fade the scene in (i.e. fade the overlay out)
StartCoroutine(FadeIn());
}
IEnumerator FadeIn()
{
//check again just in case the image somehow disappeared
if (fadeFromBlackOverlay.GetComponent<Image>() == null)
{
Debug.Log("No image component found on fadeFromBlackOverlay");
yield break;
}
//small pause
yield return new WaitForSeconds(0.5f);
//fade the overlay out (i.e. fade the scene in) over X seconds
fadeFromBlackOverlay.GetComponent<Image>().CrossFadeAlpha(0, 2.0f, false);
//as that is happening, add a delay for the same time to prevent the rest of the coroutine from running
yield return new WaitForSeconds(2.0f);
//small delay
yield return null;
//now we disable the overlay once it is transparent so that we can interact with the other things below it
fadeFromBlackOverlay.SetActive(false);
}
I'd like to emphasize here at the end that this issue only occurs in the standalone build; the script runs exactly as expected in the editor.
Thank you in advance for any suggestions you may have.
Your answer

Follow this Question
Related Questions
Fade GUI TEXT OBJECT on keypress 1 Answer
Walls are blending over each other 2 Answers
How do I repeat a part of my script? 2 Answers
Gui Text popup, fade out 1 Answer
Fade script working but I can't 'see' it working? (Solved) 1 Answer