Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: 9TOFRIDAY on December 29, 2015, 05:58:05 AM
-
hey peeps
I'm trying to create an object in a foreach loop but get this error:
"INTERNAL_CALL_Internal_InstantiateSingle can only be called from the main thread."
here is my code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
//using Facebook.Unity;
using Parse;
namespace HutongGames.PlayMaker.Actions {
[ActionCategory("DataParse")]
[Tooltip("Parse Scripts")]
public class DataParseSelect : FsmStateAction {
public FsmString UserID_, UserName_, UserGeoXLongitude_, UserGeoYLatitude_, UserVideoID_, UserVideoURL_;
string UserID, UserName, UserGeoXLongitude, UserGeoYLatitude, UserVideoID, UserVideoURL;
//luke
//public Transform prefab;
//playmaker stuff
[Tooltip("GameObject to create. Usually a Prefab.")]
public FsmGameObject gameObject;
[Tooltip("Position. If a Spawn Point is defined, this is used as a local offset from the Spawn Point position.")]
public FsmVector3 position;
[Tooltip("Optionally store the created object.")]
public FsmGameObject storeObject;
public FsmInt row;
public override void OnEnter()
{
row = 0;
DataParseQuerySelect ();
Finish ();
}
void DataParseQuerySelect()
{
try{
var query = ParseObject.GetQuery("hwsh_user_data");
query.FindAsync().ContinueWith(t =>
{
IEnumerable<ParseObject> results = t.Result;
foreach (var obj in results)
{
UserID = obj.Get<string>("User_ID");
UserName = obj.Get<string>("User_Name");
UserGeoXLongitude = obj.Get<string>("User_GeoX_Longitude");
UserGeoYLatitude = obj.Get<string>("User_GeoY_Latitude");
UserVideoID = obj.Get<string>("User_Video_ID");
UserVideoURL = obj.Get<string>("User_Video_URL");
Debug.Log(UserID.ToString() + " - " + UserName.ToString() + " - " + UserGeoXLongitude.ToString() + " - " + UserGeoYLatitude.ToString() + " - " + UserVideoID.ToString());
UserID_.Value = UserID;
UserName_.Value = UserName;
UserGeoXLongitude_.Value = UserGeoXLongitude;
UserGeoYLatitude_.Value = UserGeoYLatitude;
UserVideoID_.Value = UserVideoID;
UserVideoURL_.Value = UserVideoURL;
CreateMyMarkerObject();
//row.Value = row.Value + 1;
}
});
}
catch
{
Debug.Log ("Database query failed.");
}
}
public void CreateMyMarkerObject()
{
Debug.Log ("create my marker object");
var go = gameObject.Value;
if (go != null) {
var spawnPosition = Vector3.zero;
var spawnRotation = Vector3.zero;
var newObject = (GameObject)Object.Instantiate(go, spawnPosition, Quaternion.Euler(spawnRotation));
}
row.Value = row.Value + 1;
}
}
}
So the idea is that i am pulling information from parse. i then want to create a game object with the values. so where i am stuck at the moment is just creating a object for each entry.
please can anyone assist.
-
It seems like this is an issue with async which runs in a separate thread. Instantiate can only be called from the main thread.
Some more info:
http://stackoverflow.com/questions/24441501/main-thread-issue-with-parse-com-queries
EDIT: This might mean you need a Monobehaviour proxy to run the Coroutine. The action could then call that Monobehaviour as needed...
-
Hi,
Have you tried to base your code on my Parse support (https://hutonggames.fogbugz.com/default.asp?W1003) for PlayMaker on the wiki?
I think I bumped on this as well, and so I would suggest you study the actions I created and maybe you'll find a good base to expand on the missing features on my package.
Bye,
Jean
-
It seems like this is an issue with async which runs in a separate thread. Instantiate can only be called from the main thread.
Some more info:
http://stackoverflow.com/questions/24441501/main-thread-issue-with-parse-com-queries
EDIT: This might mean you need a Monobehaviour proxy to run the Coroutine. The action could then call that Monobehaviour as needed...
thanks for getting back to me. i will looks at your suggestion today.
-
Hi,
Have you tried to base your code on my Parse support (https://hutonggames.fogbugz.com/default.asp?W1003) for PlayMaker on the wiki?
I think I bumped on this as well, and so I would suggest you study the actions I created and maybe you'll find a good base to expand on the missing features on my package.
Bye,
Jean
actually what happened was i wrote the parse stuff myself, and only discovered your parse support yesterday. i will take a look at them and see if how you solved it. thanks so much for getting back to me.
-
Good topic and thank you jeanfabre for your hints - they helped me.
-
Thank you for your advices, i definitely use them