GeckoLib

GeckoLib

146M Downloads

[Fabric 1.18] combining animations ?

Azagwen opened this issue ยท 4 comments

commented

I have a blockEntity which has multiple "idle" animations depending on its state, one needing to constantly loop on all instances of it, and others being state-dependent.

However, when I add the animation in code testing on state, only the first animation added plays

So with the following code, only pulseAnim will play, and the controller seems to completely ignore wingFlapAnim

var wingFlapAnim = "animation.strawberry.flap_wings_loop";
var pulseAnim = "animation.strawberry.pulse_loop";

controller.setAnimation(new AnimationBuilder().addAnimation(pulseAnim).addAnimation(wingFlapAnim));

same with the opposite, with the code below, only wingFlapAnim plays, and pulseAnim is nowhere to be seen

var wingFlapAnim = "animation.strawberry.flap_wings_loop";
var pulseAnim = "animation.strawberry.pulse_loop";

controller.setAnimation(new AnimationBuilder().addAnimation(pulseAnim).addAnimation(wingFlapAnim));

my whole code in this repo if it helps
in case it is of any importance, I would also like to note that I have code-driven animations here for this block

commented

After a bit of inspection, it seems that addAnimation adds to a Queue??
Is there a way to combine animations ?

commented

Each controller can only run a single animation at a time. This is modeled after the Bedrock animation system. By calling:

controller.setAnimation(new AnimationBuilder().addAnimation(first).addAnimation(second));

You are queueing up 2 animations in a row - the second will run when the first is finished. If you want 2 animations to run at the same time, you'll need to add 2 separate controllers to your animation handling class:

@Override
public void registerControllers(AnimationData data) {
    data.addAnimationController(new AnimationController<>(this, "wings", 10, this::handleWings));
    data.addAnimationController(new AnimationController<>(this, "pulse", 10, this::handlePulse));
}

This will allow you to layer/stack animations. For more information, I would recommend reading through the wiki article on this topic, which answers your question in detail.

commented

Thanks for this precision! It worked like a charm :D

I don't know if this was mentioned in the wiki, perhaps I missed it?

commented

well this has been answered, so ima close it