Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 EmreBgdy · Jul 14, 2015 at 12:16 PM · c#unity 5databasethreadingparse

get_version can only be called from the main thread.

So I am using parse.com(a backhand database provider, made by facebook) for my unity project. I got stuck with a serious problem. Here is the explanation;

as long as i throw out my Synchronization codes from my game everything works fine but i need it in order to make the player sync their data to the server.

So here is the error im an getting:

 get_version can only be called from the main thread.
 Constructors and field initializers will be executed from the loading thread when loading a scene.
 Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.


And here is my user.cs code:

 using UnityEngine;
 using System.Collections;
 using System.Threading;
 using Parse;
 
 public class User : MonoBehaviour {
     
     public bool isAuthenticated = false;
     public string userName = null;
     public int level;
     public int exp;
     public int money;
     public GoLobby golobby;
     public Sync sync;
     public bool isGoLobbyEnabled = false;
     
 
     void Awake ()
     {
         DontDestroyOnLoad(this.gameObject);
     }
     
 
     
     void OnGUI ()
     {
         if (isAuthenticated == true) 
         {
             GUI.Box (new Rect (0,0,250,100), userName);
             //GUI.Label (new Rect (0, 15, 400, 100), "Username: " + userName);
             GUI.Label (new Rect (0, 10, 400, 100), "Level: " + level);
             GUI.Label (new Rect (0, 25, 400, 100), "Experience: " + exp);
             GUI.Label (new Rect (0, 40, 400, 100), "Money:" + money);
             if (GUI.Button (new Rect (178, 67, 70, 30), "Sync")) 
             {
                 sync.SyncToServer (userName, level, exp, money);
             }
         }
     }
 
     
     public void LoginUser(string username, string password)
     {
 
         var query = ParseObject.GetQuery("Member")
             .WhereEqualTo("Username", username)
             .WhereEqualTo("Password", password);
         query.FirstOrDefaultAsync().ContinueWith(t =>
                                        {
             ParseObject result = t.Result;
             //print (result);
             string playerName = result.Get<string>("Username");
             string playerPassword = result.Get<string>("Password");
             int playerLevel = result.Get<int>("Level");
             int playerexp = result.Get<int>("Experience");
             int playerMoney = result.Get<int>("Money");
             isAuthenticated = true;
             userName = playerName;
             money = playerMoney;
             exp = playerexp;
             sync.SyncToServer (userName, level, exp, money);
             isGoLobbyEnabled = true;
             GoLobby();
         });
     }
 
 void GoLobby()
     {
         if (isGoLobbyEnabled == true) {
             Application.LoadLevel ("Lobby");
         }
     }
 }
 




here is my sync.cs script:

 using UnityEngine;
 using System.Collections;
 using Parse;
 
 public class Sync : MonoBehaviour {
 
 
     void Awake ()
     {
         DontDestroyOnLoad(this.gameObject);
     }
 
     public void SyncToServer (string username, int level, int exp, int money)
     {
         var query2 = ParseObject.GetQuery ("Member")
             .WhereEqualTo ("Username", username);
         query2.FirstAsync ().ContinueWith (t =>
                                            {
             ParseObject obj = t.Result;
             Debug.Log (obj.ObjectId); //Works fine
             obj["Level"] = level;
             obj["Experience"] = exp;
             obj["Money"] = money;
             obj.SaveAsync();
         });
     }
 }
 




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 EmreBgdy · Jul 13, 2015 at 10:31 PM 0
Share

Not trying to be rude or something, really love Unity $$anonymous$$m but is it possible if my question can get approved asap please? As you can see it doesnt includes any illegal or bad content. Just a problem that i am having.

avatar image EmreBgdy · Jul 14, 2015 at 08:46 AM 0
Share

Dear moderators how long am i supposed to wait for approval? Atleast tell me if i broke any rules or something.

avatar image EmreBgdy · Jul 14, 2015 at 12:27 PM 0
Share

I posted the whole error here, it doesnt specify any script or a line which makes the whole process harder for me.

But I came up with something really strange. When I delete the sync parts from scripts there are no errors and everything works just fine as expected.

avatar image Dave-Carlile · Jul 14, 2015 at 12:44 PM 0
Share

Also, the Unity $$anonymous$$m isn't doing the modding here for the most part. It's just volunteers doing it in their free time. Patience young padawan.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

string/text database 0 Answers

Use a simple Database... 2 Answers

A real head-scratcher 0 Answers

SocketException: No connection could be made because the target machine actively refused it. 0 Answers

Multiple Cars not working 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