Hi everyone
Currently, I am struggling with a weird problem. I am using UnityWebRequest to retrieve data from an API and I am using async Tasks to do this. This is a basic working task which awaits the SendWebRequest() method:
But if I try to implement an async task with an await SendWebRequest() in the class [GltfAsset.cs][2] just like in my example, it doesn't work and says:
> Assets\GLTFast\GltfAsset.cs(31,13):> error CS1061:> 'UnityWebRequestAsyncOperation' does> not contain a definition for> 'GetAwaiter' and no accessible> extension method 'GetAwaiter'> accepting a first argument of type> 'UnityWebRequestAsyncOperation' could> be found (are you missing a using> directive or an assembly reference?)
Could you explain why it is working in my example? I am using the same "using's" and in my example an own class in my own namespace with no extensions..
Thanks in advance! [1]: https://github.com/atteneder/glTFast [2]: https://github.com/atteneder/glTFast/blob/master/Runtime/Scripts/GltfAsset.cs
public static async Task Request(string url)
{
UnityWebRequest request = fetchPrep(url); // function which prepares request for API fetch
await request.SendWebRequest();
if (request.isHttpError)
{
throw new System.Exception("HTTP ERROR " + request.error + url);
}
JsonSerializerSettings setting = jsonSerializerPrep();
string json = request.downloadHandler.text;
Debug.Log(json);
T fetch = JsonConvert.DeserializeObject(json);
return fetch;
}
As I said this code works and there are no errors. Now I wanted to experiment with async tasks to improve this library: [glTFast][1] But if I try to implement an async task with an await SendWebRequest() in the class [GltfAsset.cs][2] just like in my example, it doesn't work and says:
> Assets\GLTFast\GltfAsset.cs(31,13):> error CS1061:> 'UnityWebRequestAsyncOperation' does> not contain a definition for> 'GetAwaiter' and no accessible> extension method 'GetAwaiter'> accepting a first argument of type> 'UnityWebRequestAsyncOperation' could> be found (are you missing a using> directive or an assembly reference?)
Could you explain why it is working in my example? I am using the same "using's" and in my example an own class in my own namespace with no extensions..
Thanks in advance! [1]: https://github.com/atteneder/glTFast [2]: https://github.com/atteneder/glTFast/blob/master/Runtime/Scripts/GltfAsset.cs