Ah, I think I figured this out, I need explicitly write System.Object, since by default since I am inheriting from MonoBehaviour, it was using Unity’s Object
Can someone please help. I have the same issue but can’t get rid of the error. Here is my code…
public class FirebaseController : MonoBehaviour {
[System.Serializable]
public class LeaderBoardEntry : System.Object {
public string uid;
public int score = 0;
public LeaderBoardEntry() {
}
public LeaderBoardEntry(string uid, int score) {
this.uid = uid;
this.score = score;
}
public Dictionary<string, Object> ToDictionary() {
Dictionary<string, Object> result = new Dictionary<string, Object>();
result["uid"] = uid; //Line:26
result["score"] = score; //Line:27
return result;
}
}
DatabaseReference mDatabaseRef;
// Use this for initialization
void Start () {
// Set up the Editor before calling into the realtime database.
FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://downhillslalom-8c3e6.firebaseio.com/");
// Get the root reference location of the database.
mDatabaseRef = FirebaseDatabase.DefaultInstance.RootReference;
}
public void setHighscoreData(int Hscore) {
string uid = PlayerPrefs.GetString("userName");
int score = Hscore;
string key = mDatabaseRef.Child("Scores").Push().Key;
LeaderBoardEntry entry = new LeaderBoardEntry(uid, score);
Dictionary<string, Object> entryValues = entry.ToDictionary();
Dictionary<string, Object> childUpdates = new Dictionary<string, Object>();
childUpdates["/Scores/" + key] = entryValues;
mDatabaseRef.UpdateChildrenAsync(childUpdates);
}
}
I get these errors:
(26,25): error CS0029: Cannot implicitly convert type string' to UnityEngine.Object’
(27,27): error CS0029: Cannot implicitly convert type int' to UnityEngine.Object’
I could be wrong but object (lowercase o) may also work. The reason Object does not is because it thinks you are trying to use the Object class provided by unity as opposed to the built-in object type.