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
0
Question by Michellia · Mar 27, 2013 at 04:00 PM · scenevariablesavepassing

save variable from scene to scene

How to pass variable's from scene to scene in a ordinary c# script/class without it being inherited by monodevelop?

any ideas?

I attempted to make the variables static but no go.

Comment
Add comment · Show 4
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 whydoidoit · Mar 27, 2013 at 04:00 PM 0
Share

What went wrong with your statics?

avatar image Michellia · Mar 27, 2013 at 07:51 PM 0
Share

The static were wiped. If I set a boolean to true in a scene when loading the other scene its auto sets to false. With no code telling it to do that.

we do use DoNotDestroyOnLoad but that does not help.

avatar image whydoidoit · Mar 27, 2013 at 07:53 PM 0
Share

Was the thing in the static a reference to a component or game object? If it was then it's that which needs to be DontDestroyOnLoad.

avatar image whydoidoit · Mar 27, 2013 at 08:01 PM 0
Share

Statics are definitely not reset between scenes - something you are doing must be setting the value.

I attach a demonstration. Load the TestScene - its sets a static and then loads another and displays the value which remains set.

Example

teststatics.unitypackage.zip (11.8 kB)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by gribbly · Mar 27, 2013 at 07:28 PM

First option is to use PlayerPrefs:

http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.html

 PlayerPrefs.SetFloat("SaveThis", 3.0f"); //save a var called "SaveThis" as 3.0f
 
 float f = PlayerPrefs.GetFloat("SaveThis"); //f = 3.0f
 
 if(PlayerPrefs.HasKey("SaveThis")) { //test a key exists before using it }



Another option is to call DontDestroyOnLoad() on a game object in your first scene:

http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html

There are other options too, but these are the simplest.

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 Michellia · Mar 27, 2013 at 08:49 PM 0
Share

DontDestroyOnLoad does not work as per my post. But will look into the other answer you gave.

avatar image
0

Answer by Michellia · Apr 01, 2013 at 01:03 PM

So we tried everything.

We have two scene

The first scene makes a static instance of it self and a static instance of a class the is the child of the first instance.

Both have variables and the instances are static. When we load another scene we make a static instance of itself.

All three are only initialized once. we you debug.log to verify this.

But all the variables in the first scene the parent and the child are all reset to false or 0 what ever the type of variable is.

WE are trying to preserve mouselook to true and other variables.

but mouse look goes t false along with all booleans and all int go to 0, etc...

thansk all

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

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

Saving variables? 3 Answers

Saving for a Level Editor 1 Answer

Don't save gameobjects to scene file (No hide flags) 0 Answers

Make variable to select scene? 2 Answers

Passing position to function 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