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
playMe2
approach results intorun.play()
.play()
is being executed in therun
context.run
has a_mixer
property.The
playMe1
approach results intouserData.play()
.play()
is being executed in theuserData
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.