I have a general Animal scene which sets its particularities on _ready() from a resource file. Up to now, it had name, speed and sprite frames.

All sprite frames had at least the animations idle, run, eat and die, and then the Animal script just had to call $AnimatedSprite2D.play(state).

Now I want to switch to AnimationPlayer and I've seen that there's something like Animation Library, but I don't know what would be the recommended way of having the animations as a resource parameter like I had before.

I've seen you can also play animatedsprite2d's animations in an AnimationPlayer by keying the animation and the first and last frame with interpolation continuous. A quick workaround. The problem with this approach is that I must set the number of frames per animation, because it's not the same for every animal.

I have seen I can store the animation "montage" of the AnimationPlayer in a *.res file, which I imagine I could recover with animal_resource.animation_track/bundle and then call something like AnimationPlayer.add_track() or something like that, but seems off to do it like this.

So maybe you Jedis know the standard way of doing this, with the caveat that I might have 100 similar animals, so I really need this resource-based actor approach

    quimnuss I'm using 3D animation libraries, seems to work fine, everything is a Resource. You need an AnimationPlayer node on your animal(s), you click it, go to the Animation bottom panel, Animation button, Manage Animations, and that's where you create libaries and add animations to them.

    I recommend saving your library and animations in .tres text format so you can view or change them in a text editor.

    quimnuss I've seen you can also play animatedsprite2d's animations in an AnimationPlayer by keying the animation and the first and last frame with interpolation continuous. A quick workaround. The problem with this approach is that I must set the number of frames per animation, because it's not the same for every animal.

    I'm not sure I understand, but you might need to make a unique copy of the animation for each animal instance, using anim.duplicate(true) in code.

      synthnostate Nice! Animation Libraries isn't greatly documented, but sounds like on point for what I want to achieve.

      If i guess the full workflow correctly, I have to create each animation track (idle,run,die,eat) for each animal, save it as <animal>_animation_bundle.tres : AnimationLibrary and then on my data resources rabbit_data.tres just set animation_bundle to the animation library resource for that animal. What's cool about this is that I can fine-tune animations if I want.

      Then on _ready, player.add_animation for the 4 animations in animation library. Is there a way to add a whole library to a player? then on _ready, animation_player.add_animation_library("watever", resource.animation_library) Is the spritesheet set as texture of a Sprite2D stored in the track or can I "hot-swap" it on the _ready() and the player track will request the frames to the sprite agnostic to it? What I mean is, is my rabbit resource will have an animation library resource created previously with a specific Sprite2D spritesheet. Do I have to store that Sprite2D spritesheet in the resource or does the animationlibrary also store its keyed nodes somehow? I guess not.

      If not, does that mean that if I have two identically structured spritesheets I could potentially reuse the animation library?

      Ignore the animatedsprite2d called by animation_player, I like the workflow you proposed much better.

      Or would you also key in the sprite2d ctex? I'm not sure about this part

      quimnuss changed the title to [solved] Loading animation tracks from resources .

      The method works. It's more tedious because you have to change the texture, it's dimensions, and then setup the animation library. So it takes a few more steps before you see anything. Also you must not screw up the spritesheet dimensions on the resource.

      All this was included in the sprite frames, but overall it's not that different and the animation library is WAY more powerful, so it will pay off in the long run.

      Plus reusable animation library if the textures were similar enough, but unfortunately not my case.

      quimnuss changed the title to Loading animation tracks from resources .

      Hm, animation libraries are a bit clunky when moved from one scene to another. More often than not they lose the key reference to the sprite2d and there's no way to reassociate via the editor.

        quimnuss Can you... not move them?

        "Losing the reference" (UID?) sounds kinda like a bug that some of us have seen. It just has to be fixed, if not in 4.1.2 then in 4.2.

        You might have to code a little system to do what you want. Try to find other Godot games/demos that do something similar and see how they solved it.

          synthnostate Yes I could configure up the animation libraries at the animal scene but it's easier to make mistakes, overwrite stuff and harder to not forget steps.

          All this setup is to make it no-code easy to add new species to the mix, I just had to set up a resource with a sprite frames and speed and some other float stats, add it to a global enum, and voilĂ , you have a new species. Ideally without even opening godot.

          Setting up sprite frames was not ideal but ok, setting up animation libraries is not as straight forward, at that point might be better to create one scene per animal...

          For what I've seen, most projects do that, create one scene per enemy and mostly change float members of the enemy via data. The full data-driven approach I've only seen it for inventories, and since those are not animated they don't have to solve that.

          It's a pity, thought. I wish setting up the animation library would be faster, I might just drop the idea of animal from resource and do one scene per animal.