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)
To clarify…
It’s all about the context in which
play()is being executed.The
playMe2approach results intorun.play().play()is being executed in theruncontext.runhas a_mixerproperty.The
playMe1approach results intouserData.play().play()is being executed in theuserDatacontext.userDatadoes not have a_mixerproperty.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.