- Home /
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();
});
}
}
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.
Dear moderators how long am i supposed to wait for approval? Atleast tell me if i broke any rules or something.
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.
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.
Your answer
Follow this Question
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