three.js: THREE.AnimationAction: this._mixer is undefined

Description of the problem

Calling a reference to an THREE.AnimationAction fails with TypeError: this._mixer is undefined.

Im loading a json model, setting up the animations and some time later i want to play the animations. Im attaching the AnimationActions to my Object so i can play them later via myObject.playMe();. This fails with a type error, while wrapping it inside an anonymous function works:

function MyClass() {
    //...
    this.playMe1 = mixer.clipAction( mesh.geometry.animations[ 1 ] ).play; 
    this.playMe2 = function() { mixer.clipAction( mesh.geometry.animations[ 1 ] ).play() };
}

var myObjet = new MyClass();
myObject.playMe1(); // TypeError: this._mixer is undefined
myObject.playMe2(); // works
Three.js version
  • Dev
  • r82

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 25 (8 by maintainers)

Most upvoted comments

To clarify…

mesh.userData.playMe1 = run.play; 
mesh.userData.playMe2 = function() { run.play() };

It’s all about the context in which play() is being executed.

The playMe2 approach results into run.play(). play() is being executed in the run context. run has a _mixer property.

The playMe1 approach results into userData.play(). play() is being executed in the userData context. userData does not have a _mixer property.

As I mentioned over IRC, this is a Javascript idiosyncrasy. We all bumped into this eventually.

Unfortunately, I don’t think there is anything we can do to avoid users doing this.