Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[SOLVED] SceneManagement does not exist in the namespace 'UnityEngine'

Discussion in 'Editor & General Support' started by nVxx, Dec 11, 2015.

Thread Status:
Not open for further replies.
  1. nVxx

    nVxx

    Joined:
    Dec 11, 2015
    Posts:
    2
    Hi All,

    I'm currently using Unity 5.1.1f1 Pro version and want to use SceneManager.LoadSceneAsync():
    http://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html

    But Apparently UnityEngine does not contain SceneManagement namespace.

    I'm getting " SceneManagement does not exist in the namespace 'Unity Engine' " on the line:
    using UnityEngine.SceneManagement;

    The forum posts I've stumbled upon are all about Application.LoadLevel, which is obsolete in the new version:
    http://docs.unity3d.com/ScriptReference/Application.LoadLevel.html

    Thanks in advance.
     
    JynxOasisDEV and CyberShot212 like this.
  2. nVxx

    nVxx

    Joined:
    Dec 11, 2015
    Posts:
    2
    Update to Unity 5.3 fixed the issue.
     
    rtknapp28 likes this.
  3. CiberX15

    CiberX15

    Joined:
    Jul 31, 2013
    Posts:
    15
    Hurm. That did not fix it for me. I just updated to Unity 5.3.0f4 and I am stuck between Application.LoadLevel is obsolete and The name 'SceneManager' does not exist in the current context.
     
    ShashankSahu0 likes this.
  4. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Did you add
    using UnityEngine.SceneManagement;
     
  5. ashishsfb

    ashishsfb

    Joined:
    May 31, 2015
    Posts:
    3
    Adding "UnityEngine.SceneManagement;" worked for me :)
     
  6. MarleDavid

    MarleDavid

    Joined:
    Jul 1, 2016
    Posts:
    1
    Despite adding "UnityEngine.SceneManagement;" on top, I still had to write
    "UnityEngine.SceneManagement.SceneManager.LoadScene(.......
    to get it to compile...strange.
     
  7. iqbalme

    iqbalme

    Joined:
    Oct 16, 2015
    Posts:
    1
    How if we want to downgrade the script contains 'SceneManagement' ?
     
  8. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
  9. Chamandana

    Chamandana

    Joined:
    Jun 11, 2016
    Posts:
    6
    Hey guys what's the difference between Application.LoadLevelAsync and SceneManager.LoadSceneAsync (as I remember :) ) ??
     
    thelionwarriorking likes this.
  10. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @Chamandana

    Application.LoadLevelAsync just call SceneManager.LoadSceneAsync, From source code:

    Code (csharp):
    1.  
    2. [System.Obsolete("Use SceneManager.LoadSceneAsync")]
    3. static public AsyncOperation LoadLevelAsync(int index) { return SceneManager.LoadSceneAsync(index, LoadSceneMode.Single); }
    4.  
    5. [System.Obsolete("Use SceneManager.LoadSceneAsync")]
    6. static public AsyncOperation LoadLevelAsync(string levelName) { return SceneManager.LoadSceneAsync(levelName, LoadSceneMode.Single); }
    7.  
    8. [System.Obsolete("Use SceneManager.LoadSceneAsync")]
    9. static public AsyncOperation LoadLevelAdditiveAsync(int index) { return SceneManager.LoadSceneAsync(index, LoadSceneMode.Additive); }
    10.  
    11. [System.Obsolete("Use SceneManager.LoadSceneAsync")]
    12. static public AsyncOperation LoadLevelAdditiveAsync(string levelName) { return SceneManager.LoadSceneAsync(levelName, LoadSceneMode.Additive); }
    13.  
     
  11. Oblivious12

    Oblivious12

    Joined:
    Apr 15, 2017
    Posts:
    1
    [FIXED]
    Even after I use all these tips it still gives the same error message that we had in the first place. Any ideas on what might be going wrong?

    *EDIT* I Realised I had a bit of code in another script one wrong! So no need to respond, thanks to all who were going to though!
     
    Last edited: Apr 15, 2017
  12. Dubtoker

    Dubtoker

    Joined:
    Feb 11, 2016
    Posts:
    6
    if you added using scenemanagement you only have to call scenemanager.loadscene("scene01");
     
  13. WolfSensual

    WolfSensual

    Joined:
    Dec 22, 2017
    Posts:
    1
    [Fixed]Hi ^^ I have a problem with the libraries and my script can't read this lines:

    using UnityEngine;
    using UnityEngine.SceneManagement;

    Also, i have this library that not appears in other tutorials what i see

    using System.Collections.Generic;

    This is the complete code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class Controlador : MonoBehaviour {

    public void CambiarEscena(string nombre) {
    print("Cambiando a la escena " + nombre);
    SceneManager.LoadScene (nombre);
    }

    public void Salir() {
    print ("Saliendo del juego");
    }

    }

    I dont know where is the mistake.

    Sorry. I only have to reset the program
     
    Last edited: Dec 22, 2017
    bf_jeje likes this.
  14. zngb

    zngb

    Joined:
    Aug 5, 2015
    Posts:
    20
    Hmm, I had this as well but then I realized I have a script called "SceneManager" for my whole scene. See the problem? Writing SceneManager in the code was mistaken to be the MonoBehavior I had instead of what's in the 'using' directive. Renamed to GameManager and stuff works :)
     
  15. mika_2004_kv

    mika_2004_kv

    Joined:
    Mar 27, 2018
    Posts:
    1
    i still have the first problem about use SceneManager.LoadScene.
    can anybody help my?
     
  16. zngb

    zngb

    Joined:
    Aug 5, 2015
    Posts:
    20
    @mika_2004_kv - what did you try mentioned above that didn't work? Post #4 (link) on this thread should fix this.
     
  17. pradip_spixel

    pradip_spixel

    Joined:
    Jul 11, 2018
    Posts:
    3
    already add UnityEngine.SceneManagement; but it still gives error while build
     
  18. manoel3795

    manoel3795

    Joined:
    Nov 7, 2018
    Posts:
    1
    look if you are not using the updated version of visual studio, I had this problem because of the unity hub.
     
  19. nhulettwenzelmann

    nhulettwenzelmann

    Joined:
    Nov 10, 2018
    Posts:
    1
    I've tried everything you guys have said and it still doesn't work...
     
    Airmouse and msteffler like this.
  20. Milex2130

    Milex2130

    Joined:
    May 4, 2019
    Posts:
    1
    I still can't get it to work either
     
  21. RareRooster

    RareRooster

    Joined:
    Apr 17, 2017
    Posts:
    7
    If you have both...
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    They both contain a namespace for SceneManagement.
    That was causing the problem for me.

    What I did to fix it was to remove the
    Code (CSharp):
    1. using UnityEditor;
    line and use fully qualified names for Editor methods.
    Code (CSharp):
    1. UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
    In the line above, I'm using both namespaces but only fully qualifying the UnityEditor namespace.
     
    BackgroundMover and bryanlandon like this.
  22. daichiy89

    daichiy89

    Joined:
    Aug 6, 2019
    Posts:
    2
    That fixed it for me, thank you!
     
  23. Zinasterath

    Zinasterath

    Joined:
    Apr 6, 2020
    Posts:
    1
    This is a piece of code I used and it has the same thing along the bottom, saying that SceneManager doesn't exist in the name space. Any help would be greatly appreciated.

    *EDIT* Woops, I suck at spelling :') I apologize for wasting anyone's time! I found the error :D

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneMenagement;

    public class LevelLoader : MonoBehaviour
    {

    public Animator transition;

    public float transitionTime = 1f;

    // Update is called once per frame
    void Update()
    {
    if(Input.GetMouseButtonDown(0))
    {
    LoadNextLevel();
    }
    }

    public void LoadNextLevel()
    {
    StartCoroutine(LoadLevel(SceneManager.GetActiveScene().buildIndex + 1));
    }

    IEnumerator LoadLevel(int levelIndex)
    {

    transition.SetTrigger("Start");

    yield return new WaitForSeconds(transitionTime);

    SceneManager.LoadScene(levelIndex);
    }
    }
     
    Last edited: Apr 6, 2020
  24. denizkirbiyik2018

    denizkirbiyik2018

    Joined:
    May 4, 2020
    Posts:
    1
    I already have that line. Im using a tutorial.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3. public class GameManager : MonoBehaviour {
    4.     bool GameHasEnded = false;
    5.     public float restartDelay = 1;
    6.     public void GameOver ()
    7.     {
    8.         if(GameHasEnded==false)
    9.         {
    10.             GameHasEnded = true;
    11.             Debug.Log("Game Over");
    12.             Invoke("Restart", restartDelay);
    13.         }
    14.     }
    15.     void Restart (){
    16.         SceneManagement.LoadScene(SceneManagement.GetActiveScene().name);
    17.     }
    18. }
     
  25. breakadawn76

    breakadawn76

    Joined:
    May 8, 2020
    Posts:
    1
    I tried everything in this string of comments, nothing worked! I still have the same problem :(
     
    Morphite and ilhammorsalin like this.
  26. DarkAve17

    DarkAve17

    Joined:
    Jun 12, 2020
    Posts:
    1
    how to do that,
    Can you please guide me
     
  27. azaankaleem09

    azaankaleem09

    Joined:
    Jun 1, 2020
    Posts:
    3
    Assets\ball.cs(16,39): error CS0103: The name 'SceneManager' does not exist in the current context
    Assets\ball.cs(17,13): error CS0103: The name 'SceneManager' does not exist in the current context

    using UnityEngine;

    public class ball : MonoBehaviour
    {
    Vector3 _initialPosition;

    private void Awake()
    {
    _initialPosition = transform.position;
    }

    private void Update()
    {
    if (transform.position.y > 10)
    {
    string currentSceneName = SceneManager.GetActiveScene().name;
    SceneManager.LoadScene(currentSceneName);
    }
    }

    private void OnMouseDown()
    {
    GetComponent<SpriteRenderer>().color = Color.blue;
    }

    private void OnMouseUp()
    {
    GetComponent<SpriteRenderer>().color = Color.white;

    Vector2 directionToInitialPosition = _initialPosition - transform.position;

    GetComponent<Rigidbody2D>().AddForce(directionToInitialPosition * 600);
    GetComponent<Rigidbody2D>().gravityScale = 1;
    }
    private void OnMouseDrag()
    {
    Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    transform.position = new Vector3(newPosition.x, newPosition.y);
    }
    }
     
  28. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Code (csharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4. public class ball : MonoBehaviour
     
  29. frozengineer

    frozengineer

    Joined:
    Jun 25, 2020
    Posts:
    6
    Code (CSharp):
    1. using UnityEngine.SceneManagement;
    2. SceneManager.LoadScene("Game");
    you guys prolly did typo like me. Management & Manager :cool:
     
  30. KazooG

    KazooG

    Joined:
    May 4, 2020
    Posts:
    1
    yo cargo mismo error no he popdido solucionarlo
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Runtime.Hosting;
    4. using System.Runtime.InteropServices;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class Controlador :  MonoBehaviour
    8. {
    9.     //este codigo es para cambio de escena a el tutorial
    10.  
    11.     public void CambiarEscena(string nombre)
    12.     {
    13.  
    14.        
    15.         print("Cambiando escena"+nombre);
    16.         SceneManagement.LoadScene(nombre);
    17.     }
    18.  
    19.     public void Salir()
    20.     {
    21.  
    22.         print("saliendo del juego..");
    23.        
    24.         Application.Quit();
    25.    
    26.     }
    27.  
    28.  
    29. }
    30.  
     
  31. audio32

    audio32

    Joined:
    Aug 26, 2020
    Posts:
    1
    Gracias esta es la mejor respuesta que soluciona todo el problema
     
  32. RomarioRaven

    RomarioRaven

    Joined:
    Aug 9, 2018
    Posts:
    1
    I have the same problem with a UnityEngine.SceneManagement and MonoBehaviour not been recognised in VS 2015 after updating Unity to 2020 version. I made the game when i had Unity 2019 version, everything was ok. Now those namespaces aren't recognised in my VS 2015.
     
    Last edited: Sep 25, 2020
    rlopez1690 likes this.
  33. jason_skillman

    jason_skillman

    Joined:
    Feb 1, 2020
    Posts:
    11
    Not sure if this will fix it for you but I had a similar issue and figured it out.

    My editor script was in an assembly definition and I forgot to mark the assembly platform to "Editor".

    Project built just fine afterwards.
     
    luispedrofonseca likes this.
  34. ismailtopal

    ismailtopal

    Joined:
    Aug 23, 2020
    Posts:
    1
    Mine dosent work here is the code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class MainMenu : MonoBehaviour{

    public void PlayGame ()
    {
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1)

    }
    it says scene manager does not cointain a definition for LoadScene\
    EDIT:nvm i found it
     
    Last edited: Jan 28, 2021
  35. minightchannel

    minightchannel

    Joined:
    Mar 31, 2021
    Posts:
    1
    What it is, i got the same problem.
     
    duhamohsin likes this.
  36. DD-Boys

    DD-Boys

    Joined:
    May 15, 2021
    Posts:
    1
    It worked when i added
    using UnityEngine.SceneManagement;
     
  37. geet2008

    geet2008

    Joined:
    Jun 2, 2022
    Posts:
    1
    Hey guys,
    using unity 4.7.2
    I'm trying all of these methods but none of them are working out
    could I get any help to change the scene
    thx in advance
     
  38. akhileshrao

    akhileshrao

    Joined:
    Oct 11, 2020
    Posts:
    6
    Tried all amoeba methods but not working. Can someone help out?
     
  39. jlnorris

    jlnorris

    Joined:
    May 17, 2022
    Posts:
    6
    I had this problem and ended up trying something completely different. Don't know if this will help anyone but this is what I ended up doing:

    I had "using UnityEngine.SceneManagement;" and "using UnityEditor.SceneManagement;" when I had the error. I tried fully qualifying the UnityEditor commands and removing the include for them like RareRooster suggested, but still got the error.

    I realised the error was only coming up when I was actually building the game, not while using it in the editor, and I had no need for those commands at run time (they were just scripts I was running to help build a scene).

    So I put all of the UnityEditor-related commands within an "#if UNITY_EDITOR" ... "#endif" directive, and then Unity could build the game without problems.
     
    tristanarbet and andersonevanea like this.
Thread Status:
Not open for further replies.