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 xstahef · Jul 03, 2012 at 08:12 AM · staticvalue

Pass values between scenes

Hello,
Is it possible to pass values (an instance of class could be great) betweens scenes ? And genraly is it possible to define some values and access them during game (like a repository) ?
Thanks for your help.

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

3 Replies

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

Answer by diddykonga · Jul 03, 2012 at 08:17 AM

Well one of the best methods is to put in DontDestroyOnLoad() in the gameObject's code, so that way it will persist through out scenes. :)

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 xstahef · Jul 03, 2012 at 08:18 AM 0
Share

Thanks for your help, it is exactly that I need.

avatar image
1

Answer by Wolin · Jul 03, 2012 at 11:05 AM

You can create a game object with DontDestroyOnLoad() or simply make a static manager class which holds values you need (for example a score).

public class ScoreManager {

private static ScoreManager scoreManager = null;

private int score = 0;

public static ScoreManager getInstance() { if(scoreManager == null) { scoreManager = new ScoreManager(); }

return scoreManager; }

public int getScore() { return score; }

public int setScore(int score) { this.score = score; } }

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 xstahef · Jul 03, 2012 at 11:21 AM 0
Share

Thanks for sample

avatar image xikky · Mar 13, 2013 at 04:26 PM 0
Share

sorry had to wake this up again .. but does the static manager need to be in hierarchy in every scene? Or the first loaded screen would be enough to place static manager?

avatar image diddykonga · Mar 14, 2013 at 04:15 AM 1
Share

If you wanted to use a static manager like this, if its not a $$anonymous$$onoBehaviour then you can just create it once (In Code), but if it is, then either yes it needs to be in the heirechy for each level, or put DontDestroyOnLoad() in it.

avatar image
1

Answer by _EdzUp_ · Jul 03, 2012 at 12:55 PM

If you wanted to pass things like scores etc you could also use PlayerPrefs to do it, there is a limit on the size of the amount stored for the webplayer of 1Mb though.

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 xstahef · Jul 03, 2012 at 12:59 PM 0
Share

Thanks for your help. But it seems that it's like a Dictionary with key/value and value are string. As you said and you're certainly right, it is perfect for score or configuration. But at this time I need to store complex data.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using Static Value? 1 Answer

recharging value? 0 Answers

Static Variable Doesn't Change ? 0 Answers

Calling non-static from static function C# 2 Answers

Should animated game object be market as a static? 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