Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
-1
Question by WaterMinecraft · Jan 31, 2014 at 02:50 PM · save scene

Keeping variables through scenes

Hello, I am currently having this problem! (:

I have a page, 10 matches, and.. I think that's it, but when I go to the next scene, it doesn't have my information there... How do I make this happen is my question. (: Thank you!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Ashish Dwivedi · Jan 31, 2014 at 02:57 PM

The object that you want to keep persistent through scenes, you need to call "DontDestroyOnLoad (transform.gameObject)" this method once in awake or start by passing object reference.

Unity scripting reference.

Comment
Add comment · Show 7 · 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 Exalia · Jan 31, 2014 at 03:02 PM 2
Share

I currently use this method so I support this answer.

The only problem this creates is that if you have dependency on these objects for a specific scene they will always need to be created.

You can get around this by storing all your global objects in a prefab and placing them in every scene. Then running a check on if these objects already exist or are active don't initialise any more of them.

Otherwise you will try and test your second scene and it won't work entirely due to dependency from objects created in another scene.

avatar image WaterMinecraft · Jan 31, 2014 at 03:06 PM 0
Share

So... I have this on my FPS character... but it's still not working? Do I have to add multiple lines to each script?

avatar image Ashish Dwivedi · Jan 31, 2014 at 03:17 PM 0
Share

Yes, you need to call this method once for all the objects which you want to persistent through scenes.

avatar image WaterMinecraft · Jan 31, 2014 at 05:32 PM 0
Share

All right... I had this set up before... The DontDestroyOnLoad... But I'm still having the issue of missing variables..?

avatar image Ashish Dwivedi · Feb 01, 2014 at 11:58 AM 0
Share

Can you paste your code here having missing variable?

Show more comments

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

20 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

Related Questions

Unity Scene Loading Crash 0 Answers

4.6.1f1: Can't save scene 2 Answers

Scene Saving In Between Runtimes 1 Answer

Unity will not allow me to export anything, or save any new scenes 1 Answer

How i can save persistent data for each scene? 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