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
0
Question by Daniel-Gutierrez · Sep 06, 2018 at 10:00 PM · scripting problemload sceneasyncdeactivateno error

Help with Scene Changing

So I'm completely stymied trying to figure out why my scene loading isnt working.

The ideal behavior of this script is : load the starting scene the door script on the door in the active scene loads the objects in the next and deactivates them immediately, - Doors in the next scene do not cache their targets The player goes to the door and triggers it All of the gameObjects in the next scene are set to active - This causes the door in that scene to cache its destination, the first. the current scene is unloaded

What actually happens : Everything works as expected until the player gets to the first scene's door The second scene gets activated briefly The door in the second scene caches the first scene as it should Everything in the second scene is deactivated (now there are no active objects in either scene)

Here is the source code:

 public class Door : MonoBehaviour 
 {
     public string SceneToLoad;
     public Vector2 positionInOtherScene;
     bool doOnce = true;
     BinaryFormatter bf;
     FileStream file;
     GameObject player;
     Vector3 pos;
     Scene current;
     Scene otherScene;
     GameObject[] otherGos;
     GameObject[] currentGos;
 
 
     void OnEnable()
     {
         pos =  new Vector3(positionInOtherScene.x, positionInOtherScene.y , 0 );
         player = GameObject.FindGameObjectWithTag("Player");
         current = gameObject.scene;
         print("ALoading: " + SceneToLoad);
 
         if(current == SceneManager.GetActiveScene())
         {
             print("Loading: " + SceneToLoad);
             SceneManager.LoadSceneAsync(SceneToLoad,LoadSceneMode.Additive);        
             SceneManager.sceneLoaded += FinishLoading;
         }
     }
 
     void FinishLoading(Scene scene, LoadSceneMode lsm)
     {
         otherScene = SceneManager.GetSceneByName(SceneToLoad);
         otherGos = otherScene.GetRootGameObjects();
         foreach(GameObject go in otherGos)
         {
             print("deactivate : " +go.name);
             go.SetActive(false);
         }
     }
 
     void OnDisable()
     {
         print(gameObject.name + " door is now deactivated");
     }
     public void Travel()
     {
         print("hit door in scene " + gameObject.scene);
         SceneManager.MoveGameObjectToScene(player,otherScene);
         player.transform.position = pos;
         SceneManager.UnloadSceneAsync(current);
         SceneManager.SetActiveScene(otherScene);
         print("Set active scene : " + otherScene.name);
         foreach(GameObject go in otherGos)
         {
             print("activate : " +go.name);
             go.SetActive(true);
         }
 
     }
     void OnTriggerEnter2D(Collider2D col)
     {
         if(doOnce & col.gameObject.tag=="Player" & otherScene.isLoaded)
         {
             doOnce = false;
             Travel();
         }
     }
 
 
 }

alt text

capture.png (245.9 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Plz Need Help 1 Answer

Using OnSceneLoad (additive) to activate script on player within active scene 0 Answers

want to activate and deactivate a canvas by script 2 Answers

LoadSceneAsync additive and moving scene root problem 1 Answer

Loading screen with async load and freezing gameplay 0 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