- Home /
Make a simple animation viewer
Hi guys !
I'm quite new to Unity and quite bad in english, i'll try to do my best.
I'm trying to make an animation viewer in Unity. I use generic avatars, and I got some troubles to view my animations on Unity viewer builtin. The situation is: all my friends don't get 3D software to check my animations, so I would like to build an Unity scene so they can play randomly animations on a given character. It can be useful for me too, to check if they are well set at the import, before putting them in the gameplay logic.
I began to script it (C#) but i got some troubles. First I wanted to just give to the script, by the Inspector, a character Prefab and a directory where I store animation files (with animation clip inside). But I couldn't manage to give a directory as variable in the Inspector. Is there a way to do it? Or should I put it as string variable written by hand?
Then, with my animation clip list, how could I play them on my character? Is it possible to randomly chose one and play it, by the Animator Component? It's like the animation system does not really allow it. Is there some trick to do it, without building an Animation Controller state machine?
I'm here to find more advices than solutions. If you think i'm on the wrong way, and there is better ones, please tell me.
Thanks!
To access files outside your Assets folder, you need to use System.IO (Check the $$anonymous$$SDN database). You'd have to find a way to import animation files files into Unity at runtime... I don't think it's possible, though. After all, snimations are only created once the start and end frames of a clip are set in the Inspector of a model file. These things have to be done in the Editor. It might be possible to write your own importer, but it's probably better if you find another way.
No it's not the point. Animations are properly imported, by hand, from .fbx files put in the Assets folder, to generate animation clips. I just want to access the animation clips, and play them (one by one of course) on a given character. The question was, is it possible to do it without building before an AnimationController? Or maybe by building an AnimationController at runtime?
You can use the Animation component, which is the legacy animation system. It is simpler than the new Animator system. You can just put one or more clips into it and play them with the Play(clilpName) function.
But the Animation component requires legacy animation clips isn't it?
Answer by Theinsanekiller · Mar 04, 2016 at 06:51 AM
For your answer Lets go step by step, First thing you asked is, Is there are way to create an animation viewer? And the answer is Yes, and the way i am able to think is to create an app and play animations randomly so that your friends will be able to play.
Second question was: You can do with directory but the thing is you will have to provide the path where the animations are stored and its bit confusing to do it. There is a lengthy process for doing it.
Third part was: You can do with animation component but it will be far easy if you create an animation controller and create an integer variable and you assign a value for every animation and then by script you will have to get a random no. and assign it to animator and it will play a random animation.
hope this helps. @Diccy
Oh i choosed very bad words :D ! When I said "play random animation", I meant like "random access". Play any animation I want, without worrying about the states of Animation Controller.
I'm making my way to it:
in Editor only (no pb for me), I found the AssetDatabase class, to get AnimationClips of given directories (it needs an array of pathes), something like this:
List<AnimationClip> animationList;
string[] guids = AssetDatabase.FindAssets("t:AnimationClip", animationFolderPathes);
foreach (string guid in guids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
animationList.Add(AssetDatabase.LoadAssetAtPath<AnimationClip>(path));
}
And I'm looking around AnimationControllerOverride to play animation. With one unique (dummy-)state in the Controller, and changing on runtime the AnimationClip referenced in the Override. I'll test it today.