INTERNAL_CALL_Internal_RaycastTest can only be called from the main thread.
This can be really frustrating, so, what to do? We need some Magic Threads!
The below example shows how the latest version of UnityExtender allows you to make a coroutine jump back and forth between a background thread and the foreground main loop. It doesn't get much easier than this, and it integrates perfectly with Unity coroutines. This new version of UnityExtender should be available in a few days.
void Start () { MagicThread.Start(ThisIsAMagicalThread()); } IEnumerator ThisIsAMagicalThread() { Debug.Log("I am running in the background."); //This will raise an error Physics.Raycast(new Ray(Vector3.zero, Vector3.forward)); yield return new ForegroundTask(); Debug.Log("I am now running in the Unity main loop."); //This will work! Physics.Raycast(new Ray(Vector3.zero, Vector3.forward)); yield return new WaitForSeconds(2); Debug.Log("About to re-enter the background..."); yield return new BackgroundTask(); Debug.Log("I am running in the background again."); }