Getting names from the animation controller

I have a script which calls the animation controller .play function when receiving events.

I’m able to call the .play function fine but when I loop through .assets array to get animation names they are undefined. The assets array only has asset ids, everything else is undefined. How do I get the names of the animations?

//get the animation controller
for(i=0;i<this.entity.children.length;i++){
        if(this.entity.children[i].tags.has("anim")){
            animController = this.entity.children[i].animation;

        }
    }

//try to get the animation names but they are undefined

 for (var anim of animController.assets){
        console.log("name is ",anim.name);
    }

I’m sure I’m missing something here. Thanks for any help.

You are almost there! You just need in your second loop to check if the asset referenced by the anim controller is an asset id or a fully loaded asset. If it just an asset id you need to grab a reference of the actual asset instance.

There are plenty of ways in doing this, for example:

    for (var anim of this.model.animation.assets){
        
        if( isNaN(anim) === false ) anim = this.app.assets.get(anim);
        console.log("name is ",anim.name);
    } 
1 Like

That was it, thank you!

1 Like