• 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
1
Question by SamohtVII · Oct 08, 2018 at 12:35 AM · convert

Cannot implicitly convert type `string' to `UnityEngine.Object' and Firebase

I am getting an error on the code in this tutorial

https://firebase.google.com/docs/database/unity/save-data

Below is the code section I am having trouble with. I am getting the error on two lines, 26 and 27.

 result["uid"] = uid: this gives me the "Cannot implicitly convert type `string' to `UnityEngine.Object'
 result["score"] = score: this gives me the "Cannot implicitly convert type `int' to `UnityEngine.Object'


 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);
  
  
     }
 }


Please help. Thanks

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 Bunny83 · Oct 08, 2018 at 02:16 AM

I have never worked with firebase. However i'm 99% sure that your dictionary should be

Dictionary<string, object> or Dictionary<string, System.Object>

instead of

Dictionary<string, Object> which actually is Dictionary<string, UnityEngine.Object>


Keep in mind that the compiler will use classes from the namespaces you are "using". There is no "Object" class in the global namespace. Since most Unity scripts have a using UnityEngine; at the top, "Object" will refer to UnityEngine.Object.


The C# base class for every type (System.Object) has an alias name in the global namespace: object. Note the lower case "o". There are several alias names for built-in fundamental types, like string (System.String), int (System.Int32), long (System.Int64), ...

Comment
Add comment · Show 1 · 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 SamohtVII · Oct 08, 2018 at 02:33 AM 0
Share

God damn I bet that's what it is. Can't wait to get home a try it. Thank you x100000

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

Converting file types 1 Answer

Converting 'char' to the name of a variable 1 Answer

Easier way to remap mouse axis / keyboard input to iphone joysticks? 0 Answers

Convert To UnityScript 1 Answer

C# to Unity script question ? 4 Answers


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