I did the following to create an animation component and then play it programatically. But it’s not playing and also there is no errors in DevTools. What am I doing wrong?
MyScript.prototype.initialize = function () {
var self = this;
this.app.assets.loadFromUrl(’/testAnim.json’, ‘animation’, function (err, asset) {
self.entity.addComponent(‘animation’, {
assets: [asset],
speed: 1
}); console.log(self.entity.animation);
self.entity.animation.play(asset.name);
});
};
I got console.log(self.entity.animation) - ‘model’ and ‘skeleton’ properties are all ‘null’ but I see that ‘assets’ is an array of the correct asset which is ‘testAnim.json’, which I am assuming the animation json is loaded but something wrong either the json file or somewhere. Is this the right way to load an external animation?
** forgot to mention that I used Playcanvas editor to import the FBX w/ animation embedded and downloaded the model json and also animation json manually to use in my code.
I have a local http server and the /testAnim.json is located in the http root.
Apparently there is no error in the callback (err value is null) because I see self.entity.animation.assets[0] has ‘testAnim.json’ as ‘name’ value. Any ideas? Thank you for looking at this.
You are right! I created a parent entity and then attached the script, but made another entity with the model and then attached to the parent. No wonder it doesn’t work! Thank you so much!