Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question how to store in Firebase database using PlayerPrefs

Discussion in 'Scripting' started by Madfool, Jun 9, 2020.

  1. Madfool

    Madfool

    Joined:
    Feb 7, 2020
    Posts:
    6
    Hello everyone,I have unity 2019.1.02f and I wanna store PlayerPrefs data into the database, but it's not working, this is the code:

    FirebaseDatabase.DefaultInstance.GetReference("Users").Child(uid).Child("profile").Child("Field").SetValueAsync(PlayerPrefs.GetString("field"));

    the code works with another value, but when I use PlayerPrefs it doesn't work.
    Is this a correct way to do it?

    Thanks
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Two separate operations:
    • retrieving value from playerprefs
    • storing value in Firebase
    Separate them into different lines, and debug from there.

    Have you tried logging the value returned by
    PlayerPrefs.GetString("field")
    to make sure it's what you expect? That would be step 1.
     
  3. Madfool

    Madfool

    Joined:
    Feb 7, 2020
    Posts:
    6
    I did, it works perfectly, but storing the value in the database is my problem.

    Should I get the value and store it in a local variable and THEN store the variable in Firebase?
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    If getting the value works fine, there's something wrong with how you're storing it. The firebase API doesn't care, nor does it have any knowledge of where you got the value from.
     
    Joe-Censored likes this.
  5. Madfool

    Madfool

    Joined:
    Feb 7, 2020
    Posts:
    6
    Hmm, it's really strange, there are some values that are stored in Firebase in the same way, so I was wondering why this exact one didn't work, I'll have to check the rest of the code.

    Thanks anyways :)