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.