Search Unity

Bug PlayerPrefs.GetFloat returns wrong values in UWP build

Discussion in 'Windows' started by CharIliad, Aug 25, 2022.

  1. CharIliad

    CharIliad

    Joined:
    Jun 26, 2015
    Posts:
    8
    When the program calls PlayerPrefs.GetFloat() the return value is wrong. For example, we save (with SetFloat) the number "1.47" and we get (with GetFloat) the number "1069334000"
    This happens ONLY when the program starts. If during the execurtion we use SetFloat, then the GetFloat returns a correct value.
    This happens only when running on UWP. Not on editor, not on Android, not on Windows, not on iOS

    To reproduce:
    Create a new project.
    Switch to Universal Windows Platform.
    Use SetFloat to save any float number.
    Use GetFloat to load the saved number.
    After the second excecution the returned number would be wrong


    To test it I used the script below:

    Code (CSharp):
    1. public class testGetFloat : MonoBehaviour
    2. {
    3.      public TextMeshProUGUI t;
    4.      void Start()
    5.      {
    6.          float f = PlayerPrefs.GetFloat("xxx", 0.0f);
    7.          float r = Random.Range(-0.01f, 2f);
    8.          t.text = f.ToString("0.00") +" - "+ r.ToString("0.00");
    9.          PlayerPrefs.SetFloat("xxx", r);
    10.      }
    11.  
    12. }
     
  2. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    408
    This issue was also raised on this thread.

    I notified the dev team, but please file a bug if you haven't already.
     
    CharIliad likes this.
  3. CharIliad

    CharIliad

    Joined:
    Jun 26, 2015
    Posts:
    8
    Thanks. I reported the bug.
     
  4. CharIliad

    CharIliad

    Joined:
    Jun 26, 2015
    Posts:
    8