Siccity / GLTFUtility

Simple GLTF importer for Unity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Animation doesn't work on android!

Robo233 opened this issue · comments

I used this code to download the model from the web. It is a .gltf version of a model from https://www.mixamo.com/#/

 public IEnumerator DownloadModelCoroutine(string url, string path){
    if(File.Exists(path)){
        Debug.Log("Found model locally");
        LoadModel(path);
    }else{
        using (UnityWebRequest webRequest = UnityWebRequest.Get(url)){
            webRequest.downloadHandler = new DownloadHandlerBuffer();
            yield return webRequest.SendWebRequest();
            if(webRequest.result == UnityWebRequest.Result.ConnectionError || webRequest.result == UnityWebRequest.Result.ProtocolError){
                Debug.Log(webRequest.error);
                model = null;
            }else{
                File.WriteAllBytes(path, webRequest.downloadHandler.data);
                LoadModel(path);
            }
        }
    }
}

And this for the animation:

void LoadModel(string path){
    AnimationClip[] animClips;
    var i = new ImportSettings();
    i.useLegacyClips = true;
    model = Importer.LoadFromFile(path,i, out animClips);
    if (animClips.Length > 0){
        Animation anim = model.AddComponent<Animation>();
        animClips[0].legacy = true;
        animClips[0].wrapMode = WrapMode.Loop;
        anim.clip = animClips[0];
        anim.Play();
    }
}

It works perfectly in the editor, but after I build it for android, the model is loaded but the animation doesn't work. I'm using Unity 2022.2.7 and also tried Unity 2022.1.23 and Unity 2021.3.19. I also tried different versions of the GLTFUtility package. I tried with both .gltf and .glb files but it doesn't work. I used the Android Logcat and it says "Default clip could not be found in attached animations list".