So I'm trying to execute a UnityWebrequest, which needs to start from a Coroutine.
Now trying to Debug everything at some point I figured out calling the Coroutine from the Start function works (receiving the Debug.Log messages), but calling it from a normal function it will not work (I do not receive the debug messages within GetRequest
).
Hence I think that for some reason the Coroutine is not running on the main-thread (as also no error appears).
Does anybody know how I can enforce a Coroutine to run on the main-thread or another solution to my issue?
Here you'll find the code where WebGet
is being called from a class that is not in Monobehaviour, but the class containing WebGet & GetRequest
is.
(Please ignore the request variable within WebGet
this will be for a later stage.
public UnityWebRequest WebGet(string url)
{
Debug.Log("This is the URL Get " + url);
var request = UnityWebRequest.Get(url);
Debug.Log("Request URL: " + request.url);
StartCoroutine(GetRequest(url));
Debug.Log("After Coroutine");
return request;
}
private IEnumerator GetRequest(string url)
{
var request = UnityWebRequest.Get(url);
Debug.Log("This is the URL inside coroutine " + url);
yield return request.SendWebRequest();
if (request.isNetworkError)
{
Debug.Log("Error While Sending: " + request.error);
}
else
{
Debug.Log("Received: " + request.result);
}
}