- Home /
Question by
fractalwrongness · Jul 13, 2014 at 12:56 AM ·
c#asyncthreads
Change a gameObject property at runtime from another thread
I'm trying to update a TextMesh's text property at runtime from a separate thread (as a Task). However, I get the following errors.
System.ArgumentException: set_text can only be called from the main thread.
Constructors and field initializers will be executed
from the loading thread when loading a scene.
If it's helpful, here is a representative sample of code:
private void FetchStuffAsync(){
var query = ParseObject.GetQuery("Blah");
query.FindAsync().ContinueWith(t => {
IEnumerable<ParseObject> results = t.Result;
foreach(ParseObject ob in results){
myTextMesh.text = "blahblahblah";
break;
}
});
}
Do I have to wrap the TextMesh in a separate class and carry out the update through its methods? How can I change the text as soon as I get the information?
Comment