Forum begins after the advertisement:


[Part 9.5] Scene doesn’t load because scene fader remains black

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 9.5] Scene doesn’t load because scene fader remains black

Viewing 15 posts - 1 through 15 (of 33 total)
  • Author
    Posts
  • #16416
    tai
    Level 8
    Former Patron
    Helpful?
    Up
    0
    ::

    Hi, i am trying out the Part 9.5 project files the project worked fine but all the ability is unlock so i delete all the save files in the folder C:\Users\phamh\AppData\LocalLow\DefaultCompany\Metroidvania Tutorial.

    View post on imgur.com

    When i reload the project and open from Main Menu scene its normal but when i clicked Play the screen turned black and i can only hear sound in the background as in the video.

    I have tried redownload the project files but its not working anymore.

    #16425
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Can you go to the Build Settings and see if all the Scenes are added in there?

    #16426
    tai
    Level 8
    Former Patron
    Helpful?
    Up
    0
    ::

    Yes everthing is added.

    #16444
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    That is strange. Try expanding the Cave_1 file in your Scene after loading the new level:

    View post on imgur.com

    I suspect the Scene is loading, but the Scene Fader isn’t deactivating so it looks like the scene isn’t loading.

    #16447
    tai
    Level 8
    Former Patron
    Helpful?
    Up
    0
    ::
    #16448
    tai
    Level 8
    Former Patron
    Helpful?
    Up
    0
    ::

    Yesterday, I tried to do part 9 from scratch in another project and it worked fine but I havent done pause menu and audio yet.

    #16453
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    If you are still working on the 9.5 files, try changing the Start() to Awake() in SceneFader and see if it fixes the issue. More information here: https://blog.terresquall.com/community/topic/part-5-article-changes-common-issues-bugfixes/

    #16455
    tai
    Level 8
    Former Patron
    Helpful?
    Up
    0
    ::

    Here is the SceneFader.cs. It already changed to Awake when i downloaded it.

    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;
    
    public class SceneFader : MonoBehaviour
    {
        public float fadeTime;
    
        private Image fadeOutUIImage;
    
        public enum FadeDirection
        {
            In, 
            Out
        }
    
        // Start is called before the first frame update
        void Awake()
        {
            fadeOutUIImage = GetComponent<Image>();
        }
    
        // Update is called once per frame
        void Update()
        {
    
        }
    
        public void CallFadeAndLoadScene(string _sceneToLoad)
        {
            StartCoroutine(FadeAndLoadScene(FadeDirection.In, _sceneToLoad));
        }
    
        public IEnumerator Fade(FadeDirection _fadeDirection)
        {
            float _alpha = _fadeDirection == FadeDirection.Out ? 1 : 0;
            float _fadeEndValue = _fadeDirection == FadeDirection.Out ? 0 : 1;
    
            if(_fadeDirection == FadeDirection.Out)
            {
                while(_alpha >= _fadeEndValue)
                {
                    SetColorImage(ref _alpha, _fadeDirection);
    
                    yield return null;
                }
    
                fadeOutUIImage.enabled = false;
            }
            else
            {
                fadeOutUIImage.enabled = true;
    
                while (_alpha <= _fadeEndValue)
                {
                    SetColorImage(ref _alpha, _fadeDirection);
    
                    yield return null;
                }
            }
        }
    
        public IEnumerator FadeAndLoadScene(FadeDirection _fadeDirection, string _sceneToLoad)
        {
            fadeOutUIImage.enabled = true;
    
            yield return Fade(_fadeDirection);
    
            SceneManager.LoadScene(_sceneToLoad);
        }
    
        void SetColorImage(ref float _alpha, FadeDirection _fadeDirection)
        {
            fadeOutUIImage.color = new Color(fadeOutUIImage.color.r, fadeOutUIImage.color.g, fadeOutUIImage.color.b, _alpha);
    
            _alpha += 0.02f * (_fadeDirection == FadeDirection.Out ? -1 : 1);
        }
    }
    </code>
    #16466
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Try adding this line to SceneTransition. That should fix it:

        private void OnTriggerEnter2D(Collider2D _other)
        {
            if (_other.CompareTag("Player"))
            {
                GameManager.Instance.transitionedFromScene = SceneManager.GetActiveScene().name;
    
                PlayerController.Instance.pState.cutscene = true;
                PlayerController.Instance.pState.invincible = true;
                if(UIManager.Instance.sceneFader == null)
                    UIManager.Instance.sceneFader = UIManager.Instance.GetComponentInChildren<SceneFader>();
                StartCoroutine(UIManager.Instance.sceneFader.FadeAndLoadScene(SceneFader.FadeDirection.In, transitionTo));
            }
        }

    The problem is likely that UIManager loads after SceneTransition, causing UIManager.Instance.sceneFader to be null and breaking the sceneFader transition.

    #16470
    tai
    Level 8
    Former Patron
    Helpful?
    Up
    0
    ::

    Tried it but sadly not working. There are still the same error in console.

    #16472
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Can you show me your UIManager, SceneTransition and SceneFader scripts?

    #16485
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    I found the issue Tai. Check your Pause Menu’s Quit to Main Menu button and make sure you unpause the game when the button is clicked. Otherwise, the game remains paused when you quit and return to the level, causing the screen to remain black.

    Quit to Main Menu
    #16510
    tai
    Level 8
    Former Patron
    Helpful?
    Up
    0
    ::

    Sorry for not reply sooner. I have set everything and the game is not freeze when started anymore. But when Resume button is pressed everything is not unpaused.

    This is the Quit to Main Menu button

    This is Resume button

    Here is the video of the problems

    #16514
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Check whether the UnPauseGame() function is fired when you click on the Resume button.

    #16521
    tai
    Level 8
    Former Patron
    Helpful?
    Up
    0
    ::

    How do i check it

Viewing 15 posts - 1 through 15 (of 33 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: