setAnimation method
Switches the current animation (keeps the loaded resource), posing it on its first frame. Does not start playback — play does.
Selecting the animation already selected does nothing at all. It is a
switch, so with nothing to switch to it costs nothing and disturbs nothing:
the playhead stays, the instance children are not rebuilt, and the override
layer survives. That is what makes it safe for a state machine to assert
its current clip every frame — and returning early is not just an
optimisation, because _applyTransportSettings writes the loop count and
the Brain RE-ARMS the remaining-loop counter on every write. Re-asserting
each frame would reset the loop budget each frame, and a finite loopCount
would never run out.
To restart, call play, which heads out. To drop the overrides, call clearAllPartOverrides. To drop a playback section, set one covering the whole animation.
A switch folds the track stack back to track 0 alone: overlays, fades and sources go, and so do every track's alpha, blend and SsTrackSync — set them again after it. Track 0's playback settings stay. The animation a crossfade left is currentAnimation, so naming it does nothing, and naming the one the crossfade left behind switches back to it.
Implementation
bool setAnimation(String name) {
final internal = _requireInternal();
// Against what is actually selected, which [load] resets — so a second pack
// that happens to name an animation the same way as the first still gets
// set up rather than being taken for one already selected.
if (_currentAnimation == name) return true;
final ok = internal.setupAnimation(name);
if (!ok) {
_reportMissingAnimation(name);
} else {
_currentAnimation = name;
_reportedMissingAnimation = null;
_latchCanvas(name);
_applyRoot();
// The Brain reset the loop count; restore the cached settings so a
// mid-session animation switch (or [reload]) keeps the caller's loop count
// instead of silently reverting to infinite looping.
_applyTransportSettings(internal);
}
notifyListeners();
return ok;
}