Forum begins after the advertisement:
[Part 5] Heart and Mana UI disappear after adding in the scene fader
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 5] Heart and Mana UI disappear after adding in the scene fader
- This topic has 1 reply, 2 voices, and was last updated 2 days, 16 hours ago by
Sean Ng.
-
AuthorPosts
-
June 12, 2026 at 11:58 pm #19761::
Got everything looks perfect in the UI but when i add the Scene Fader and start the game, the Mana Container and the Heart Container just disappear and the Scene fader transition doesn’t even run when transition to another scene Here is the code i have written for the Scene Fader
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class SceneFaded : MonoBehaviour { [SerializeField] private float fadeTime; private Image fadeoutImage; public enum FadeDirection { In, Out } private void Awake() { fadeoutImage = GetComponent<Image>(); } public void CallFadeandLoad(string _sceneLoad) { StartCoroutine(FadeandLoad(FadeDirection.In, _sceneLoad)); } public IEnumerator Fade(FadeDirection _fadeDirection) { float _alpha = _fadeDirection == FadeDirection.Out ? 1 : 0; float fadeEnd = _fadeDirection == FadeDirection.Out ? 0 : 1; if (_fadeDirection == FadeDirection.Out) { while (_alpha > fadeEnd) { SetColor(ref _alpha, _fadeDirection); yield return null; } fadeoutImage.enabled = false; } else { fadeoutImage.enabled = true; while (_alpha < fadeEnd) { SetColor(ref _alpha, _fadeDirection); yield return null; } } } public IEnumerator FadeandLoad( FadeDirection _fadeDirection, string _sceneLoad) { fadeoutImage.enabled = true; yield return Fade(_fadeDirection); SceneManager.LoadScene(_sceneLoad); } void SetColor(ref float _alpha, FadeDirection _fadeDirection) { fadeoutImage.color = new Color(fadeoutImage.color.r, fadeoutImage.color.g, fadeoutImage.color.b, _alpha); _alpha += Time.deltaTime * (1 / fadeTime) * (_fadeDirection == FadeDirection.Out ? -1 : 1); } }Here is the code i have written for the UIManager
using System.Collections; using System.Collections.Generic; using UnityEngine; public class UIManager : MonoBehaviour { public static UIManager Instance; private void Awake() { if (Instance == null) { Instance = this; Destroy(gameObject); } else { Instance = this; } DontDestroyOnLoad(gameObject); } public SceneFaded sceneFaded; private void Start() { sceneFaded = GetComponentInChildren<SceneFaded>(); } }June 14, 2026 at 12:38 pm #19762::Hello Anh, when running your code the UI Manager keeps getting deleted, on your end when you run can you see if the UI Manager gets deleted? As within your
UIManager.cstheAwake()it make the UI Manager a static instance but immediately destroy itself removing the UI Manager which in turns delete the health, mana and scene fade along with it.using System.Collections; using System.Collections.Generic; using UnityEngine; public class UIManager : MonoBehaviour { public static UIManager Instance; private void Awake() { if (Instance == null) { Instance = this; Destroy(gameObject); } else { Instance = this; } DontDestroyOnLoad(gameObject); } public SceneFaded sceneFaded; private void Start() { sceneFaded = GetComponentInChildren<SceneFaded>(); } }Please change the portion highlighted above to the one below and it should be fixed
using System.Collections; using System.Collections.Generic; using UnityEngine; public class UIManager : MonoBehaviour { public static UIManager Instance; private void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } DontDestroyOnLoad(gameObject); } public SceneFaded sceneFaded; private void Start() { sceneFaded = GetComponentInChildren<SceneFaded>(); } } -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: