#Help understanding List

1 messages · Page 1 of 1 (latest)

safe flint
#

Hello, I'm following a tutorial for setting up a scene manager that runs from a List (allowing for adding/removing scenes). In the video their code runs perfectly but for me, it keeps adding scenes. I distilled the code down to the smallest/simpliest example I could. What happens is Debug.Log() outputs an infinitely incrementing number....1,2,3,4....

Scene Script

public class InitController : MonoBehaviour
{
    private void Start()
    {
        SceneController.instance.Add((int)SceneIndex.Splash);
        SceneController.instance.Load();
    }
}

Scene Manager Script

public class SceneController : MonoBehaviour
{
    // Singleton
    public static SceneController instance;

    List<AsyncOperation> scenesActionList = new List<AsyncOperation>();

    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
    }
    public void Add(int sceneIndex)
    {
        scenesActionList.Add(SceneManager.LoadSceneAsync(sceneIndex, LoadSceneMode.Additive));
    }

    public void Remove(int sceneIndex)
    {
        scenesActionList.Add(SceneManager.UnloadSceneAsync(sceneIndex));
    }

    public void Load(bool loadingScreen = false)
    {
        StartCoroutine(LoadingProgress());
    }

    public IEnumerator LoadingProgress()
    {
        Debug.Log(scenesActionList.Count);
        yield return null;
    }
}
fiery spear
#

If the scene you're loading contains the InitController script then it'll always run again when the scene has loaded

safe flint
#

The scene I'm loading doesn't contain the InitController.

fiery spear
#

If there's nothing else then that's the only reason why it would happen

#

Put Debug.Log(name + " runs InitController's Start"); in the InitController's Start method and verify

safe flint
#

So you are right...I'm trying to load the splash scene and the output is "SplashContrller runs InitController's Start" over and over...but I don't understand why....here is the SplashController script:

#
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Threading.Tasks;
using System.Collections;
using System;

public class SplashScript : MonoBehaviour
{
    public GameObject logo;
    private Renderer logoRenderer;
    public float AnimationSpeed;
    public float AnimationStart;

    private void Awake()
    {
        logoRenderer = logo.GetComponent<Renderer>();
        logoRenderer.material.SetFloat("Stage", AnimationStart);
    }

    void Start()
    {
        StartCoroutine(AnimationSequence());
    }
    private IEnumerator AnimationSequence()
    {
        yield return StartCoroutine(AnimationLogo());
        yield return StartCoroutine(SceneRedirect());
    }

    private IEnumerator AnimationLogo()
    {
        float dissolveCurrent = AnimationStart;
        while (dissolveCurrent >= 0)
        {
            dissolveCurrent -= AnimationSpeed;
            logoRenderer.material.SetFloat("_Stage", dissolveCurrent);
            yield return null;
        }
    }
    private IEnumerator SceneRedirect()
    {
        yield return new WaitForSeconds(2);
        //SceneManager.LoadScene("Scenes/Intro/Loading/Loading"); 
    }
}
#

Nothing about Init at all

fiery spear
#

It prints the object's name, not a script's name

#

look at what components the SplashController has

safe flint
#

omg...you totally got it

#

thank you so much.

#

I think it was because I copied and pasted it at one point that it ended up in there.