Feasible -Dynamically create everywhere Animation actions at runtime before opening Quick Look/WebXR

Some way to at runtime add an animation to an Animator’s runtime AnimationController would be really handy for use cases like this I think, then I could get them by name

by user 103054507105067008

Totally agree! There should be some methods to easily add states / animations to the AnimatorController and not having to worry about the underlying data structure.

I’m just doing R&D on this really so if that is something that might land I can very easily jump to use that with what I’m trying to do here - for now I’m still using the Animation component so at least on desktop, animations in a loaded model can be played back :slightly_smiling_face:

by user 103054507105067008

I have an internal list of things to look through for project templates to make future projects smooth to set up and get going with but that was top priority as I do a lot of product viewer stuff for AR

by user 103054507105067008

Changed the channel name: Feasible -Dynamically create everywhere Animation actions at runtime before opening Quick Look/WebXR

by user 103054507105067008

I’ll add something like this for the next version to make this easier

Brilliant! I will test that out soon as I can :green_heart::pray:

by user 103054507105067008

@ROBYER1 you can try it with the latest version

Should I be using it like this?

            this.new as Object3D,
            Animator,
            false
          );

          //anim.animations = [firstAnimation];
          anim.runtimeAnimatorController = AnimatorController.createFromClips(
            args.detail.animations
          );

by user 103054507105067008

I get AnimatorController.createFromClips is not a function

by user 103054507105067008

Sounds like youre not using the correct version. Have you tried restarting vscode?

Here’s my test component:

export class AnimatorControllerGen extends Behaviour {

    @serializable(AnimationClip)
    clips?: AnimationClip[];

    awake() {
        console.log(this.clips);
        const animator = this.gameObject.getComponent(Animator);
        if (animator) {
            const controller = AnimatorController.createFromClips(this.clips!);
            animator.runtimeAnimatorController = controller;
        }
        console.log(animator);
    }

}
```using the latest version

A clean install got it working!

by user 103054507105067008

With PlayAnimationOnClick, is there something I need to do to refresh it and get it working afer setting up my Animator and linking it to the component here at runtime?

          var buttonClickComp =
            spawnedButton?.getComponent(PlayAnimationOnClick);
          if (buttonClickComp && this.new) {
            buttonClickComp.target = this.new.transform;
            buttonClickComp.animator = anim;
            buttonClickComp.stateName =
              anim.runtimeAnimatorController.model.layers[0].stateMachine.states[1].name;
            buttonClickComp.stateNameAfterPlaying =
              anim.runtimeAnimatorController.model.layers[0].stateMachine.states[0].name;
            console.log("cickplaycomp", buttonClickComp);
          }

by user 103054507105067008

What do you mean? Sorry
The state names are just the names of your animationclips btw - are those maybe null/empty?

Yeah the state values themselves seem to be empty
image.png

by user 103054507105067008

I’m loading a glb file at runtime, using your new function to set up an animator with animationcontroller on it with the animations added then instantiating a gameobject with the PlayAnimationOnClick component on it before I set the stateName and other variables on the PlayAnimationOnClick component but clicking it does nothing

by user 103054507105067008

You’re just setting stateName and stateNameAfterPlaying above tho

The other variables are private that I need to set it seems :confused:

by user 103054507105067008

image.png

by user 103054507105067008