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 Entyro · Oct 21, 2014 at 03:46 PM · menulevelsettings

Save information on Level Load HELP

Hi there!

I have a problem when I load a new level for my game. I have a settings menu where I can change sound volume, quality etc.

When I, for example, turn the sound off and load the game, it works fine, but if I'm going back to the main menu by using my pause menu, the sound plays as it was before the setting change.

This happens with every setting I change, everything changes back to deffault.

Do you guys have any clue how to fix this problem?

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
Best Answer

Answer by unitygamer · Oct 21, 2014 at 04:28 PM

1.create a script called settings or whatever

  • call DontDestroyOnLoad(this) in Start() or Awake()

  • add volume, quality etc variables to it

  • parent to an empty GameObject

  • store or set value through it

or else you could use playerprefs like PlayerPrefs.SetInt("volume ",volumeVariable);

PlayerPrefs.SetInt("quality", qualityvar);

and get it via PlayerPrefs.GetInt("volume", volumeVariable);

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 Entyro · Oct 21, 2014 at 06:04 PM 0
Share

Thanks for the answer! I tested around a little bit and tried using static variables ins$$anonymous$$d. That seems to work, but I read that you should avoid using them.

Is it that bad to use them? $$anonymous$$aybe it doesn't make the game slower if I use them for only 3 variables

avatar image unitygamer · Oct 21, 2014 at 06:18 PM 1
Share

its ok using 3 static variables

however as you add more ,you could use the ' don't destroy on load' as you dont have to declare a lot of static variables.

btw using playerprefs will save your player's setting for the next gameplay session as well ,so most people use it for playername , quality,volume and all other stuff.

avatar image Kiwasi · Oct 21, 2014 at 06:26 PM 1
Share

Static variables will have no effect on your game speed. They are perfectly fine for variables that truly are static, like sound volume. They get a bad rep because so many beginners misuse them.

Static variables can also create hidden dependencies in your code. This can be a nightmare if you intend to reuse your code.

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

28 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Main Menu Problem 0 Answers

OnCollisionEnter called twice 2 Answers

Help! I downloaded Unity, but everytime i open it, it shuts down! How do i fix this?? 0 Answers

Block Placing Script Help 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