Search Unity

SceneManager.SceneLoaded method showing overload error

Discussion in 'Scripting' started by Kaivris, Sep 24, 2020.

  1. Kaivris

    Kaivris

    Joined:
    Sep 12, 2017
    Posts:
    1


    I double checked my code against Unity's documentation and it matches, but I'm still getting this error: "No overload for 'OnSceneLoaded' matches delegate 'UnityAction<Scene, LoadSceneMode>"

    Code (CSharp):
    1. void OnEnable()
    2. {
    3.    SceneManager.sceneLoaded += OnSceneLoaded;
    4. }
    5.  
    6. void OnDisable()
    7. {
    8.   SceneManager.sceneLoaded -= OnSceneLoaded;
    9. }
    10.  
    11. void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    12. {
    13.    if (firstPlay) return;
    14.    //load saved data to strings
    15.    LoadSaveGameData();
    16.    //destroy all of the objects that are going to be loaded
    17.    DestroyAllSaveableObjectsInScene();
    18.    //load saved objects from strings
    19.    CreateGameObjects();
    20. }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    Can you show the full script?

    Do you have any scripts in your project named "Scene" or "LoadSceneMode"?
     
    sasha2010rusin and LilHati like this.
  3. LilHati

    LilHati

    Joined:
    May 12, 2018
    Posts:
    3
    Praetor had it right for me at least - I forgot I had created an enum called "scene" in that same class.
     
  4. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    This is the 2nd time I've googled for this answer. So I'm commenting that the solution was, for me, also that I had a script called "Scene". Must change that :D
     
    jumabek4044 and PraetorBlue like this.