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 7rigger · Apr 02, 2010 at 03:46 PM · positionscene

Retaining/restoring position information when loading scenes

Hi all,

I'm pretty new to Unity (but learning fast, thanks to the awesome people here!) and I am having a problem when loading between scenes.

In the game I am making, the player is able to travel to different points from the same base level. The problem I am having is that when the player reloads the main level after visiting one of the side levels, they always appear at the same position - in the center of the map, say.

I know there must be some ability to store the players x,y,z co-ordinates when they leave the level and re-apply them when they return (so that they appear in the same place they were in before they left), but I am a n00b when it comes to coding really so I'm not sure how it would be accessed. Could anyone give an example, or point out any examples of this kind of coding I could learn from?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by KvanteTore · Apr 02, 2010 at 04:28 PM

One way would be to use PlayerPrefs to store the previous position in a level when a new level is loaded. This PlayerPrefs is stored between sessions, so the positions would be remembered the next time the player plays the game.

Another option is to create a GameObject with the purpose of keeping track of the position in the visited levels, and use DontDestroyOnLoad to keep this object from being destroyed when a new level is loaded.

Another option is to store the position in a static variable. These variables persist between scene loads.

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 7rigger · Apr 04, 2010 at 09:34 AM 0
Share

I got the static variable system working, thank you for your help :) now I need to look into playerprefs (you can never learn too much!)

avatar image KvanteTore · Apr 04, 2010 at 09:48 AM 0
Share

Heh. Thanks lucas. Static vars are probabbly the easiest solution :)

avatar image
2

Answer by Cyclops · Apr 06, 2010 at 06:19 PM

Here's an example project I posted, which creates a permanent LevelManager that other scripts can access for variables: Simple Demo of a LevelManager.

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 7rigger · Apr 07, 2010 at 11:51 AM 0
Share

Thank you very much for this. Im pretty new to coding, so the comments explaining it were a big help to me :)

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

No one has followed this question yet.

Related Questions

Bug with Unity's Scene Arrows 2 Answers

Swapping between Scenes without affecting objects position. 2 Answers

Raycast from mouse position in editor scene view? 1 Answer

Application.Loadlevel when z greater than x 2 Answers

How to keep position of a Game Object when switching scene? 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