• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Dec 06, 2016 at 04:43 PM by stevenc33 for the following reason:

The question is answered, right answer was accepted

avatar image
35
Question by stevenc33 · Apr 20, 2016 at 06:07 PM · onlevelwasloaded

Since OnLevelWasLoaded is deprecated (in 5.4.0b15) What should be use instead?

Since OnLevelWasLoaded is deprecated (in 5.4.0b15) What should be use instead?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image psychentist · Nov 05, 2016 at 06:00 AM 0
Share

In JS, I just used

 function OnLevelFinishedLoading () {
 //do stuff
 }

ins$$anonymous$$d of OnLevelWasLoaded.

It seems to be working fine for what I used it for.

3 Replies

  • Sort: 
avatar image
94
Best Answer

Answer by Addyarb · Aug 30, 2016 at 02:36 PM

Since a reliable coding example hasn't come up in the first few Google searches, I thought I'd post the new suggested implementation here.

The old way:

 void OnLevelWasLoaded (int level)
 {
 //Do Something
 }

The new way:

     using UnityEngine.SceneManagement;
             void OnEnable()
             {
              //Tell our 'OnLevelFinishedLoading' function to start listening for a scene change as soon as this script is enabled.
                 SceneManager.sceneLoaded += OnLevelFinishedLoading;
             }
         
             void OnDisable()
             {
             //Tell our 'OnLevelFinishedLoading' function to stop listening for a scene change as soon as this script is disabled. Remember to always have an unsubscription for every delegate you subscribe to!
                 SceneManager.sceneLoaded -= OnLevelFinishedLoading;
             }
         
             void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
             {
                 Debug.Log("Level Loaded");
                 Debug.Log(scene.name);
                 Debug.Log(mode);
             }

Note that 'OnLevelFinishedLoading' is a name that I've made up. You can name your method whatever you like.

What you're seeing in the OnEnable and OnDisable functions are delegate subscriptions. This simply means that we are setting a function of our choice (in this case, 'OnLevelFinishedLoading') to listen to the SceneManager for a level change.

Also note, that since this delegate has two parameters (Scene and SceneMode), that you must include those two parameters as well - even if you don't plan on using that information in your function.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DgoodingIndi · Aug 31, 2016 at 11:36 PM 1
Share

thank you, been looking all over for a simple code example.

avatar image ChrisSch · Sep 15, 2016 at 05:29 AM 0
Share

Thanks, was also looking for a simple example. :)

avatar image catfink · Sep 26, 2016 at 05:36 PM 3
Share

The problem is that this doesn't actually work as the timing of the new event is different to OnLevelWasLoaded. When I tested this implementation I found that the scene isn't actually fully loaded when the new event fires (which it is when OnLevelWasLoaded is called) and as such this method is not reliable. We have a unity forum thread open on this which unity are looking at to determine what should be done to resolve this problem ..... http://forum.unity3d.com/threads/important-function-deprecated-what-is-the-new-alternative.424746/

avatar image Tuitaio · Jun 24, 2017 at 11:12 PM 1
Share

I had to use UnityEngine.Scene$$anonymous$$anagement.Scene, because Unity apparently has a class Scene that wasn't what I was looking for, and it was causing parameters match error. It took a while to figure it out, so I'm leaving it here if someone encounters the same problem.

avatar image Estecka · Dec 15, 2017 at 09:03 AM 0
Share

Would the sceneLoaded event be called before all Awake() in the scene or after ?

Show more comments
avatar image
12

Answer by tkamruzzaman · Dec 06, 2016 at 04:04 PM

Instead of using Onlevelwasloaded(), add a delegate to SceneManager.sceneLoaded to get notifications after scene loading has completed.

  using UnityEngine.SceneManagement;
 
   void OnEnable() {
      SceneManager.sceneLoaded += OnSceneLoaded;
  }
 
  void OnDisable() {
      SceneManager.sceneLoaded -= OnSceneLoaded;
  }
 
  private void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
   //do stuff
  }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wilbertllama · Mar 09, 2017 at 02:45 AM 0
Share

Hello,

I have Unity 5.5.1 (64bit) and Vuforia to try to augment things. In “Console – Clear on play”, I always get this message:

"OnLevelWasLoaded was found on VuforiaAbstractBehaviour

This message has been deprecated and will be removed in a later version of Unity. Add a delegate to Scene$$anonymous$$anager.sceneLoaded ins$$anonymous$$d to get notifications after scene loading has completed"

How do I delegate to Scene$$anonymous$$anager.sceneLoaded? I would like to get the notifications after I press on the play button. For example, whether my webcam can pick up the image target or not.

avatar image
7

Answer by Dave-Carlile · Apr 20, 2016 at 06:31 PM

The SceneManager class has events you can hook into for scene changes/loading/etc.

Specifically, the SceneManager.sceneLoaded event.

Note that these aren't in the docs for 5.3 and were added in 5.4 seemingly.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

77 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

OnLevelWasLoaded not called at all 3 Answers

OnLevelWasLoaded Problem was Found On 2 Answers

OnLevelWasLoaded was not called 0 Answers

OnSceneWasLoaded deprecated - cannot find work around 2 Answers

OnLevelWasLoaded deprecated, trying to setup my buttons 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges