Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
2
Question by Fregloin2 · Dec 14, 2015 at 09:40 AM · onlevelwasloaded

OnLevelWasLoaded not called at all

Hello. I have a problem. My project has only one scene. I need get event like OnLevelWasLoaded to apply some additional settings to my game objectst. Unfortunally this method not called at all. I put some breakpoints in debugger to watch execution of this method, but they weren't called after game starting. P.S. I start game from editor. May be it will work if i build and run standalone app?? P.P.S Awake methods in the same objects are called, but OnLevelWasLoaded aren't.

Here some of my code:

public class ConfiguratorFile : MonoBehaviour {

 public    void    OnLevelWasLoaded(int level) {
     Debug.Log("Level loaded"); //just for test
     //this method is never called :(
 }

 public    void    Awake() {
     //this method is called
     //DocumentManager.Instance.LoadFromFile("links.xml"); //singleton
 }

}

This scipt is attached to empty gameobject.

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by zanyang1103 · Jan 05, 2016 at 10:06 AM

alright ,i got the same problem...

i was working on a demo project which only contains one scene

in the editor mode ,OnLevelWasLoaded was not called when i first press play button,then it was called everytime after i used SceneManager.LoadScene(SceneManager.GetActiveScene().name); to reload the scene。

however,in the .exe file i build from this project ,it was called right after the game started.

so here is what i thought, in editor when we start the scene ,the environment is diffent from the real game environment,and the editor doesn't consider this as a new scene loaded。

to prove this ,i add a new scene which only contains a camera ,and add a script with this:

 void Start()
 {
     SceneManager.LoadScene("main");
 }

"main" was the name of my previous scene,so when the new scene loaded ,it just load my main scene. this time ,OnLevelWasLoaded was called as it should be.

don't know why they design it this way,hope this will help you.

Comment
Add comment · Show 2 · 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 zanyang1103 · Jan 05, 2016 at 10:09 AM 0
Share

forget to mention, i use the 5.x version.

avatar image Longman006 · Feb 18, 2016 at 07:42 PM 0
Share

Had the exact same problem and I'm still curious as to why it works differently in the editor and the .exe is it a bug or are we just doing something wrong ?

avatar image
1

Answer by Susajin · Dec 14, 2015 at 10:27 AM

as far as i know OnLevelWasLoaded will not be called when you just start the game.

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
avatar image
0

Answer by avetokhin · Jan 12, 2016 at 03:08 AM

I have the same problem. Create new project -> Add empty object with such script:

         void Awake ()
         {
             print ("Awake");
         }
     
         void OnLevelWasLoaded (int index)
         {
             print ("OnLevelWasLoaded with index " + index);
         }
 

When I run it in editor OnLevelWasLoaded is not invoked on start, but when I build exe file it is. It looks strange and must be a bug. Actually I faced with this problem in roguelike-2d tutorial when tried to test build.

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 Johnny_13 · Sep 20, 2016 at 03:38 PM 0
Share

yup, i had same issue with roguelike tutorial. only it didn't run in exe either. weird

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

40 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

Related Questions

Since OnLevelWasLoaded is deprecated (in 5.4.0b15) What should be use instead? 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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges