Skip to content

State machine advancement only supports small increments? #402

@saward

Description

@saward

Description

I'm trying to use Rive animations within motion canvas. I'm using the low level js runtime to animate, and it's working. However, I've noticed that when using advanceAndApply with large jumps, the state machine does not advance in the expected way, as though there's a maximum dt that it can handle. I've got a solution that seems to work that involves ensuring that the jumps for advanceAndApply remain under 0.1 seconds.

Is this a known limitation? I'd like to understand what's going on here, so I can better avoid the situation. Sometimes I need to jump ahead, as I use the motion canvas timeline to jump back and forth to sections.

Provide a Repro

Here is the splitting up that works for state machines (AI provided fix for me that worked):

    // Handle state machine advancement
    const SKIP_THRESHOLD = 0.1; // seconds - anything above this is considered a skip
    if (dt > SKIP_THRESHOLD) {
      // Timeline skip detected - advance state machine in small increments
      const frameTime = 1 / 60; // 60 FPS
      let remainingTime = dt;

      while (remainingTime > 0) {
        const stepTime = Math.min(remainingTime, frameTime);
        this.stateMachine.advanceAndApply(stepTime);
        this.stateMachineTime += stepTime;
        remainingTime -= stepTime;

        // Safety break
        if (remainingTime < 0.001) break;
      }
    } else {
      // Normal playback - advance normally
      this.stateMachine.advanceAndApply(dt);
      this.stateMachineTime += dt;
    }

    // advance everything else normally
    this.animation.advance(dt);
    this.animation.apply(1);
    this.artboard.advance(dt);

Expected behavior

State machine advances correctly based on any sized number of seconds, and does not need to be manually broken down.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions