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 Ssiroo · Jul 31, 2014 at 03:19 PM · javascriptplayerprefssave

Playerprefs not saving

Hello,

Im trying to make a script to save the player settings like volume and field of view.It used to work before but it suddenly stopped for some reason.This is the script Im using(a part of it actually) :

 var FOV : float = 75;
 var mainCamera : Camera;
 var bulletCamera : Camera;
 var field = PlayerPrefs.GetFloat("FOW");
 var velume : float = 1;
 var valume = PlayerPrefs.GetFloat("Volume");
 var player : Transform;
 
 function Awake()
 {
     FOV = field;
     velume = valume;
 }
 
 function OnGUI ()
 {
 GUI.skin = myGUISkin;
 
             if (menu1==true) 
             {
 
                  if (GUI.Button(Rect(Screen.width/2.5,Screen.height/2.03,Screen.width/5,Screen.height/10),"Field Of View: " + FOV.ToString("f0")))
                     {
                  }
                  
                 
                 FOV = GUI.HorizontalSlider (Rect ( Screen.width/2.5,Screen.height/1.7, Screen.width/5, Screen.height/10), FOV, 50, 150);
                 mainCamera.fieldOfView = FOV;
                 bulletCamera.fieldOfView = FOV;
                 Camera.main.fieldOfView = FOV;
                 PlayerPrefs.SetFloat("FOW", FOV);
                 PlayerPrefs.Save();
                 
                  if (GUI.Button(Rect(Screen.width/2.5,Screen.height/1.65,Screen.width/5,Screen.height/10),"Volume: " + velume.ToString("f0")))
                     {
                  }
                  
                 velume = GUI.HorizontalSlider (Rect ( Screen.width/2.5,Screen.height/1.4, Screen.width/5, Screen.height/10), velume, 0, 10);
                 player.audio.volume = velume / 10;
                 PlayerPrefs.SetFloat("Volume", velume);
                 PlayerPrefs.Save();
    }
 }


This is the player script(a part of it) :

 var pauseMenu : PauseMenu;
 var valume : PauseMenu;
 
 function Start()
 {
     pauseMenu = GetComponent(PauseMenu);
     audio.volume = pauseMenu.valume;
     Camera.main.fieldOfView = pauseMenu.FOV;
 }


Now the volume won't even change anymore with the slider.This is really frustrating.It worked before, I don't remember making any changes to it. Any little help would be really appreciated.

Thank you for your time.

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 commodore · Jul 31, 2014 at 03:30 PM 0
Share

There might be a problem with the way your playerprefs were stored. Delete them and see if it works after

 PlayerPrefs.DeleteAll();
avatar image commodore · Jul 31, 2014 at 03:39 PM 0
Share

Or you might have other playerprefs you don't want deleted so do

 PlayerPrefs.Delete$$anonymous$$ey("Volume");
 PlayerPrefs.Delete$$anonymous$$ey("FOW");

PlayerPrefs has a size limit. Could it be that it's full?

avatar image Ssiroo · Jul 31, 2014 at 04:12 PM 0
Share

Neither of the options you gave me worked. When you say that PlayerPrefs has a size limit, how can I actualy know when it's full. I only have 2 playerprefs by the way, the ones shown on the main question.

avatar image rutter · Jul 31, 2014 at 04:21 PM 1
Share

The PP size limit on WebPlayer builds is 1$$anonymous$$B, and you'll know you hit it if SetFloat and friends start throwing a PlayerPrefsException.

Currently, you're running those GetFloat calls using field initializers. Those sometimes cause problems if they're run during the scene load. You might try moving them to Awake to see if that helps.

1 Reply

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

Answer by Ssiroo · Jul 31, 2014 at 04:48 PM

I replaced this line :

player.audio.volume = velume / 10;

with this one :

AudioListener.volume = velume;

And it somehow worked.

Also I replaced these lines :

 var field = PlayerPrefs.GetFloat("FOW");
 var velume : float = 1;
 var valume = PlayerPrefs.GetFloat("Volume");
 var player : Transform;
  
 function Awake()
 {
     FOV = field;
     velume = valume;
 }

with these :

 var FOV : float = 75;
 var mainCamera : Camera;
 var bulletCamera : Camera;
 var velume : float = 1 / 10;
 var player : Transform;
 
 function Awake()
 {
     FOV = PlayerPrefs.GetFloat("FOW");
     velume = PlayerPrefs.GetFloat("Volume");
 }


Thank you everyone for trying to help me, I really appreciate it!

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

24 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

Related Questions

Playerprefs save player position 3 Answers

Game/editor stops responding when going to Highscores 0 Answers

How can i get the following script back on track to being a single level high score saver 0 Answers

Tracking and targeting one of multiple objects 1 Answer

Highscrore won't work 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