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 /
avatar image
6
Question by TSRajesh · Mar 24, 2016 at 01:58 AM · scenesevents

How to.. "Add a delegate to this to get notifications"..

HI All, Am using the 5.4 beta. (Just got b11). In the SceneManagenment, there are few events

  • activeSceneChanged

  • sceneLoaded

  • sceneUnloaded

Their descriptions says like.. "Add a delegate to this to get notifications when the active scene has changed"

Have no ideas how i can do that. Can someone kindly provide an example?

For loading, since I use Load Async, I could do it in a coroutine like yield return SceneManager.LoadSceneAsync(...) But the other two.. How do i get a notification, or wait in a coroutine?

Thanks

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
10
Best Answer

Answer by Bunny83 · Mar 24, 2016 at 02:33 AM

I don't have 5.4 beta and it's documentation isn't online, so i have no idea how the signature of those events look like. SceneManagenment is a namespace and a namespace can't contain events. Is it possible that those events are inside the SceneManager class?

If those events don't have any parameters you can simply do:

 void Awake()
 {
     SceneManager.activeSceneChanged += MyMethod; // subscribe
 }
 void OnDestroy()
 {
     SceneManager.activeSceneChanged -= MyMethod; // unsubscribe
 }
 
 void MyMethod()
 {
     Debug.Log("active scene changed");
 }

However if the event takes a parameter (a Scene object for example) you have to declare a method that matches the signature of the event type.

Again, this is based purely on speculations since i don't have the beta version.

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 TSRajesh · Mar 24, 2016 at 03:07 AM 1
Share

Thank You. That is what I needed. BTW, 5.4 beta documentation is online.. http://docs.unity3d.com/540/Documentation/ScriptReference/index.html But I believe it is incomplete. There is absolutely no details on these events. But I could get the parameter from the error messages... For instance, UnityEngine.Scene$$anonymous$$anagement.sceneLoaded(UnityEngine.Scene$$anonymous$$anagement.Scene, UnityEngine.Scene$$anonymous$$anagement.LoadScene$$anonymous$$ode) But I got What I Wanted.

avatar image bueda · Sep 16, 2016 at 08:01 AM 5
Share

To elaborate on this if anybody else finds this question: From introspecting UnityEngine.dll, I found out the types of these events:

 UnityAction<Scene, Scene> activeSceneChanged;
 UnityAction<Scene, LoadScene$$anonymous$$ode> sceneLoaded;
 UnityAction<Scene> sceneUnloaded;

The UnityAction-Type behaves like a regular C# delegate, so you can subscribe as @Bunny83 showed. However, the function signature needs to be a tad different. The type arguments to the UnityAction describe the argument types that subscribing functions need to expect. For example, to subscribe to activeSceneChanged, you would write:

 void Awake()
 {
   Scene$$anonymous$$anager.activeSceneChanged += $$anonymous$$y$$anonymous$$ethod;
 }
 void $$anonymous$$y$$anonymous$$ethod(Scene previousScene, Scene newScene)
 {
   Debug.Log("active scene changed");
 }
avatar image
5

Answer by tkamruzzaman · Nov 08, 2016 at 03:56 AM

 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 · 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
3

Answer by stalematestudio · Nov 16, 2016 at 10:54 PM

this is just a useless reacharound injected for no other purpose than to break code and caries no benefit

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 fidelsoto · Jan 03, 2017 at 06:12 PM 1
Share

I think they're trying to decouple everything that has to do with scene management from the core of the engine and keep it all under the Scene$$anonymous$$anagement class.

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

44 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

Related Questions

How to teleport to different scenes? 2 Answers

objects not reappearing 2 Answers

click gameobject, go to the next scene? 2 Answers

How to put seperate scenes together into one game 1 Answer

NGUI Button some how unclickable 3 Answers


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