Siccity / GLTFUtility

Simple GLTF importer for Unity
MIT License
976 stars 217 forks source link

Async loading cause "JsonReaderException: Unexpected character encountered while parsing value: g. Path '', line 0, position 0." #224

Open SwatiScorpbit opened 1 year ago

SwatiScorpbit commented 1 year ago

Hey, GLB Sync loading is working but when I try Async method it causes "Jason reader exception", here is the full script:

private void Update()
{
    if (Input.GetKey(KeyCode.L))
    {
        ImportGLTFAsync(gltfFileLocation);
    }
}

[ContextMenu("Import GLTF")]
void ImportGLTFSync()
{
    loadedGameObject = Importer.LoadFromFile(gltfFileLocation);
    RotatingObject rotatingObject = loadedGameObject.AddComponent<RotatingObject>();
    rotatingObject.target = loadedGameObject.transform;
    rotatingObject.roationSpeed = 15f;
}

void ImportGLTFAsync(string filepath)
{
    Importer.ImportGLTFAsync(filepath, new ImportSettings(), OnFinishAsync);
}

private void OnFinishAsync(GameObject arg1, AnimationClip[] arg2)
{
    Debug.Log("Finished importing " + arg1.name);
}

Error Log: JsonReaderException: Unexpected character encountered while parsing value: g. Path '', line 0, position 0. Newtonsoft.Json.JsonTextReader.ParseValue () (at /root/repo/Src/Newtonsoft.Json/JsonTextReader.cs:1817) Newtonsoft.Json.JsonTextReader.Read () (at /root/repo/Src/Newtonsoft.Json/JsonTextReader.cs:429) Newtonsoft.Json.JsonReader.ReadAndMoveToContent () (at /root/repo/Src/Newtonsoft.Json/JsonReader.cs:1240) Newtonsoft.Json.JsonReader.ReadForType (Newtonsoft.Json.Serialization.JsonContract contract, System.Boolean hasConverter) (at /root/repo/Src/Newtonsoft.Json/JsonReader.cs:1197) Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) (at /root/repo/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:202) Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) (at /root/repo/Src/Newtonsoft.Json/JsonSerializer.cs:904) Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) (at /root/repo/Src/Newtonsoft.Json/JsonSerializer.cs:883) Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) (at /root/repo/Src/Newtonsoft.Json/JsonConvert.cs:831) Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) (at /root/repo/Src/Newtonsoft.Json/JsonConvert.cs:787) Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) (at /root/repo/Src/Newtonsoft.Json/JsonConvert.cs:720) Siccity.GLTFUtility.Importer+<>cDisplayClass16_0.b__0 () (at Library/PackageCache/com.siccity.gltfutility@ac70aeb919/Scripts/Importer.cs:286) System.Threading.Tasks.Task1[TResult].InnerInvoke () (at <9aad1b3a47484d63ba2b3985692d80e9>:0) System.Threading.Tasks.Task.Execute () (at <9aad1b3a47484d63ba2b3985692d80e9>:0) Rethrow as AggregateException: One or more errors occurred. (Unexpected character encountered while parsing value: g. Path '', line 0, position 0.) System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) (at <9aad1b3a47484d63ba2b3985692d80e9>:0) System.Threading.Tasks.Task1[TResult].GetResultCore (System.Boolean waitCompletionNotification) (at <9aad1b3a47484d63ba2b3985692d80e9>:0) System.Threading.Tasks.Task`1[TResult].get_Result () (at <9aad1b3a47484d63ba2b3985692d80e9>:0) Siccity.GLTFUtility.Importer+d16.MoveNext () (at Library/PackageCache/com.siccity.gltfutility@ac70aeb919/Scripts/Importer.cs:289) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <86acb61e0d2b4b36bc20af11093be9a5>:0)