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
3
Question by mafiozooo · Mar 23, 2016 at 01:03 PM · positionplayerscenecharacter

How Move Player between Scenes?

Okay so I made this script To Enter Level2

 // Use this for initialization
 void OnTriggerEnter(Collider FPSControllerr)
 {
     if (FPSControllerr.gameObject.tag == "Player")
     {
         DontDestroyOnLoad(FPSControllerr.gameObject);
         Application.LoadLevel("Level2");   
     }
 }

And its somewhat working. But when I try to go back

        // Use this for initialization
 void OnTriggerEnter(Collider FPSControllerr)
 {
      if (FPSControllerr.gameObject.tag == "Player")
      {
       DontDestroyOnLoad(FPSControllerr.gameObject);
        Application.LoadLevel("MainLevel");
     }
 }

I get 2 FPScontrolers (which is my player) and the game crashes :( Any solutions ?

Comment
Add comment · Show 2
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 roddles · Sep 27, 2017 at 05:02 PM 0
Share

$$anonymous$$gest avoiding answers that use DontDestroyOnLoad with Unity 5.3+: according to documentation for multi-scene editing:

It is recommended to avoid using DontDestroyOnLoad to persist manager GameObjects that you want to survive across scene loads. Ins$$anonymous$$d, create a manager scene that has all your managers and use Scene$$anonymous$$anager.LoadScene(, LoadScene$$anonymous$$ode.Additive) and Scene$$anonymous$$anager.UnloadScene to manage your game progress.

avatar image roddles roddles · Sep 27, 2017 at 05:09 PM 0
Share

This calls out manager objects specifically, but I think that's just an artifact of the type of objects typically previously, back when Scenes were called Levels; the main things people would persist were manager objects. With the flexibility of multiple-scene/additive Scene loading, all kinds of objects are now being used across scene boundaries, and this bit of advice applies to any objects you'd want to use across scene boundaries.

7 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by Glonojad · Mar 23, 2016 at 04:48 PM

You can use the SceneManager to move GameObject between scenes.

                 if (FPSControllerr.gameObject.tag == "Player")
                 {
                     Scene sceneToLoad = SceneManager.GetSceneByName("Level2");
                     SceneManager.LoadScene(sceneToLoad.name, LoadSceneMode.Additive);
                     SceneManager.MoveGameObjectToScene(FPSControllerr.gameObject, sceneToLoad);
                 }

Comment
Add comment · Show 5 · 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 mafiozooo · Mar 23, 2016 at 06:08 PM 0
Share

did not work I don't know what I'm suppose to do ... ?

using UnityEngine; using System.Collections;

public class ExitAsylum : $$anonymous$$onoBehaviour {

 // Use this for initialization
 void OnTriggerEnter(Collider FPSControllerr)
 {
     if (FPSControllerr.gameObject.tag == "Player")
     {
    Scene sceneToLoad = Scene$$anonymous$$anager.GetSceneByName("Horror"); //Horror is my main level
         Scene$$anonymous$$anager.LoadScene(sceneToLoad.name, LoadScene$$anonymous$$ode.Additive);
         Scene$$anonymous$$anager.$$anonymous$$oveGameObjectToScene(FPSControllerr.gameObject, sceneToLoad);
     }


 }

}

avatar image Ali-hatem mafiozooo · Mar 23, 2016 at 06:54 PM 0
Share

by the way why you need to keep player between scenes you can add the player to each scene this is what been done by all developers it's weird to keep it because if you don't destroy you still have to make it a prfab & drooped in to all scenes so it's position will be determent.

avatar image mafiozooo Ali-hatem · Mar 23, 2016 at 06:56 PM 0
Share

holy sh*t man .. that's actually really good idea , but still I need him to be in front of the doors when I get out of the house , which is not the starting position of the player..

Show more comments
avatar image shieldgenerator7 · Oct 13, 2017 at 02:55 AM 0
Share

Scene$$anonymous$$anager.$$anonymous$$oveGameObjectToScene was exactly what I was looking for! Thanks!

avatar image
2

Answer by RomanLed · Oct 07, 2016 at 09:22 PM

Don't use Don'tDestroy, use additiveSceneLoading... this is how.... https://www.youtube.com/watch?v=S9h_iu4Zx5I&feature=youtu.be

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
1

Answer by Detinator10 · Mar 23, 2016 at 09:26 PM

I would just have the player's position set to the door when it loads the new scene. So have it use DontDestroyOnLoad and then just run a function after you change scenes that places your character wherever it needs to be. That would be the simplest way to do it.

Another thing, if your player is still getting duplicated, you could briefly transition to a blank scene with the player object when your game starts, set the player to not destroy and then load the regular scene. That way there isn't a player game object as part of your scene, only one from a different scene that you never return to

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 mafiozooo · Mar 23, 2016 at 09:52 PM 0
Share

okay lets say I have 3 different houses and I want to enter the 1st and get out in front of it and then enter the second and get out in front of it ... is there a possible script to move player when I get out of certain scene ? @ali-hatem @Detinator10

avatar image
1

Answer by Eudaimonium · Mar 24, 2016 at 10:00 PM

I wrote an article on this particular problem a while back.

DontDestroyOnLoad needs a bit more work.

http://www.sitepoint.com/saving-data-between-scenes-in-unity/

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 Ali-hatem · Mar 23, 2016 at 04:25 PM

attach a script to the player to keep it active & delete the don't destroy from your script above & in player script you only need this :

 void Start(){
 DontDestroyOnLoad(gameObject);
 }
Comment
Add comment · Show 3 · 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 mafiozooo · Mar 23, 2016 at 05:46 PM 0
Share

should I make variable before ? I'm new to scripting and I really cant seem to get it ...

avatar image Ali-hatem mafiozooo · Mar 23, 2016 at 06:10 PM 0
Share

so did this worked with you & if you need variables to persist so you don't lose score or something when switch to another scenes add variables to this script & access it from another scripts because every thing in this script will not be destroyed & lastly does player will be destroyed in someway by enemy or something .

avatar image mafiozooo Ali-hatem · Mar 23, 2016 at 06:44 PM 1
Share

did not work... my point is to to enter a door and the next scene is the house inside , after that I want to get out of the door and to be in the "main scene" but infront of the house not at my starting position :/

  • 1
  • 2
  • ›

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

12 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

Related Questions

How to keep same player settings from the scene in the .exe file 0 Answers

Understanding Prefabs + Player Spawn Points 2 Answers

How to keep position of a Game Object when switching scene? 3 Answers

Load a Scene and Move the Player to an Specific Location. 6 Answers

Camera rotation around player while following. 6 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