KhronosGroup / UnityGLTF

Runtime glTF 2.0 Loader for Unity3D
MIT License
1.81k stars 491 forks source link

How do I load Mecanim animations on the Android platform? #788

Open WalkerMe opened 1 week ago

WalkerMe commented 1 week ago

Describe the bug 💬

I need to load some animation resources directly without going through Unity's import process. Using the code below, it runs normally in the Editor, but on Android, the loaded Clip is incorrect and the action cannot be played.

`public async Task Load(string uri) { string dir = URIHelper.GetDirectoryName(uri); ImportOptions options = new() { AnimationMethod = AnimationMethod.Mecanim, ImportNormals = GLTFImporterNormals.None, ImportTangents = GLTFImporterNormals.None, // ImportContext = new GLTFImportContext(GLTFSettings.GetOrCreateSettings()), DataLoader = new UnityWebRequestLoader(dir), AsyncCoroutineHelper = UITools.GetOrAdd(GameRunner.Inst.gameObject), };

string fileName = Path.GetFileName(uri);
GLTFSceneImporter importer = new(fileName, options)
{
    SceneParent = null,
    Collider = GLTFSceneImporter.ColliderType.None,
    IsMultithreaded = false,
};
await importer.LoadSceneAsync(-1, false, _OnLoadComplete);
AnimationClip[] clips = importer.CreatedAnimationClips;
if (null == clips || 0 == clips.Length) return null;
Object.Destroy(importer.LastLoadedScene);
importer.Dispose();
return clips[0];

} `

Steps to reproduce 🔢

Loading Mecanim animations from glTF files on the Android platform is bound to fail.

Files to reproduce the issue ♻

No response

Editor Version 🎲

2022.3

Render Pipeline and version

URP

UnityGLTF Version

2.13.0

Operating System 👩‍💻

Android

When does this problem happen?

Additional Info 📜

No response

Validations 🩹

pfcDorn commented 5 days ago

hey, because we can't create Animator Controllers outside of the Editor (Unity restrictions), you need to add the animation to an existing Animator Controller.

From the readme: image

Have you already try that or is there another importing issue (when yes, please provide a sample file) ?