Error: Cannot read properties of undefined (reading 'getRestPose')

Hey!
I’m working on adding an avatar in the scene and moving it onclick. I have added the avatar and animation separately (as it is needed) and used this example as a reference: https://playground.babylonjs.com/#14GLAR#4

When I click on “Move” button, I get -
Error: Cannot read properties of undefined (reading ‘getRestPose’) and the functionality fails.
In default condition, animations are working fine.

Hello and welcome to the Babylon community! As we suggest on our template, it’s suggested you add your own playground with your code so we can have a better idea of how to help :slight_smile:

This is a part of my code that is concerned with the issue. Thank You!

Your code has a syntax error

Yeah @carolhmj. :sweat_smile: I just fixed it.

Hmmm I’m still not seeing anything on the PG? :thinking:

Hi @carolhmj! You can now see my avatar on PG. I have tried using Github to access the animation file that I’m using locally on my laptop. The error is appearing when I try to execute the ‘moveAvatar’ functionality.

You’re getting CORS errors from the assets… Using External Assets In the Playground | Babylon.js Documentation (babylonjs.com)

1 Like

@carolhmj I’m not getting the CORS error anymore. The error says Cannot read properties of undefined reading (“getRestPose”).

The target of the animations you are loading are being disposed, and therefore the animation has no target. this is the reason for the exception (line 54 in your playground).

3 Likes

Hi @RaananW!
I thought the same but I’m loading the mesh and animations separately. The ‘mesh.dispose()’ line is to dispose the mesh of the glb file that I’m using to get Animations.

I’m not sure if the problem is due to the dispose line or something else. If you’re sure, can you suggest me a solution.

There are two problems in your PG:

  • the “Armature” node is named “Armature.001” in the 2nd avatar:
    image
    I used “Armature” instead of “Armature.001” when searching for children in the PG below but a better fix would be to correct the naming in the DCC tool. Also, you should pass avatarMesh and not armatureMesh to copy() otherwise “Armature” will not be found when searching for children (destMesh.parent does not go high enough in the hierarchy if destMesh==armatureMesh)
  • the 3rd anim is a morph target animation, not a rigged animation. You should skip it in the copy() function.

Here’s a corrected PG:

3 Likes