Fader problem

I think I have everything correct in my code but when I start game fader doesn’t fade in


stays like this

Show us the code. Start with Portal.cs and Fader.cs


Oh, wait. Actually, I need to see the SavingWrapper.cs. And please paste the code, not a screenshot

using RPG.Saving;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

namespace RPG.SceneManagement
{
    public class SavingWrapper : MonoBehaviour
    {
        const string defaultSavingFile = "save";
        [SerializeField] float fadeInTime = 0.2f;

        private void Awake()
        {
            StartCoroutine(LoadLastScene());
        }

        private IEnumerator LoadLastScene()
        {
            yield return GetComponent<SavingSystem>().LoadLastScene(defaultSavingFile);
            Fader fader = FindObjectOfType<Fader>();
            fader.FadeOutImediately();
            yield return fader.FadeIn(fadeInTime);
        }

        void Update()
        {
            if (Input.GetKeyDown(KeyCode.L))
            {
                Load();
            }
            if (Input.GetKeyDown(KeyCode.S))
            {
                Save();
            }
            if (Input.GetKeyDown(KeyCode.Delete))
            {
                Delete();
            }
        }

        public void Save()
        {
            GetComponent<SavingSystem>().Save(defaultSavingFile);    
        }

        public void Load()
        {
            GetComponent<SavingSystem>().Load(defaultSavingFile);   
        }

        public void Delete()
        {
            GetComponent<SavingSystem>().Delete(defaultSavingFile);
        }

    }
}

You load the scene before fading out. It should

  • Fade out
  • Load the scene
  • Fade in

You also want your LoadLastScene to happen in Start like Sam suggested

private IEnumerator Start()
{
    // Get the fader
    Fader fader = FindObjectOfType<Fader>();
    // Fade out
    fader.FadeOutImmediately();
    // Load the scene
    yield return GetComponent<SavingSystem>().LoadLastScene(defaultSavingFile);
    // Fade in
    yield return fader.FadeIn(fadeInTime);
}

Not sure if this will help. I tested your configuration on my own game and it works (not well). Do you have a PersistentObjects somewhere in your scene?

It didn’t helped me and Yes I have PersistentObjects in my scene after
I start a game

Sorry, I meant when it’s not running. If there’s another PersistentObjects or Fader in the scene when the game’s not running it can cause trouble.

Can you take a screenshot of the hierarchy (with the Sandbox expanded) when the game is running and your screen is black like in your first screenshot. I would like to see what’s in the scene. And expand the DontDestroyOnLoad scene, too, please

I solved this problem bro thanks for your help, appreciate man.

OK, great! Do you mind sharing what the problem was and how you fixed it?

Just copied code from commit

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms