简体   繁体   中英

PARSE + Unity3d freezing from a query

 public ParseObject TheRow; public void GetCharacterData(){ string UserName=ParseUser.CurrentUser.Username; var query = ParseObject.GetQuery ("Character").WhereEqualTo ("user", UserName); query.FirstAsync().ContinueWith(t =>{ TheRow = t.Result; PlayerPrefs.SetString("UserName",TheRow.Get<string>("user")); PlayerPrefs.SetString("Some",TheRow.Get<string>("SomeData")); // No save data ( I use PlayerPrefs from an other thread than MainThread ) Debug.Log(PlayerPrefs.GetString("UserName")); }); Debug.Log("UserName",TheRow.Get<string>("user")); // Null reference } 

Why? Assigning t.Result to TheRow in an asynchronous block of code but I'm trying to access it outside that block, so TheRow is going to be null...Parse methods need some time ...

How can I rewrite that?

After one sleepless night I fixed it and I made this API. PS: Thanks for your help anyway :)

https://github.com/RealStyle12/Parse-and-Facebook-Unity3d

Try changing:

ParseObject TheRow = query.FirstAsync().Result;

to:

ParseObject TheRow = await query.FirstAsync();

EDIT: Reading the manual for the method ( http://parse.com/docs/dotnet/api/html/T_Parse_ParseQuery_1.htm )

Looks like your probelm is the .Result blocking an async task somewhere, as example all use await.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM