How to Access Meshes for Animation Control

Hi there,

I have been searching this forum quite a while, but I am still stuck.
I have a *.babylon with an animated Suzanne with activated Autostart.

But how can I access different meshes by name, so I can Start and Stop Animation later based on user Input?

GetMeshByName returns undefined for me.
The Meshes are called “Suzanne” and “StaticCube”.
Can someone point me in the right direction?

Thank you very much!

Playground is here:
https://www.babylonjs-playground.com/#I21U1Y#1

for (m in newMeshes){
    if (newMeshes[m].name == "Suzanne"){
        scene.stopAnimation(newMeshes[m]);
    }
}

(m : indices, newMeshes[m] : meshes)
Save as var and refer it later and call stopAnimation function.

var mesh = BABYLON.SceneLoader.ImportMesh("", "https://raw.githubusercontent.com/HGieselmann/BjsTests/master/", "suzanne.babylon", scene, function (newMeshes) {
    console.log(scene.getMeshByName("Suzanne").name);
}); 

output: Suzanne
also worked

Hey man,
thank you!
Worked like a Charm!

1 Like

So the animation is tied to a particular mesh on the import or is imported all inclusively under the guise of a mesh