# root.skeleton.getBoneByName is not a function

**URL:** <https://discourse.threejs.org/t/root-skeleton-getbonebyname-is-not-a-function/32538>\
**Category:** Questions\
**Tags:** loaders, animation\
**Created:** [December 10, 2021, 4:48am UTC](https://discourse.threejs.org/t/root-skeleton-getbonebyname-is-not-a-function/32538 "2021-12-10T04:48:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![0x88](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/0x88/32/20992_2.png) [@0x88](https://discourse.threejs.org/u/0x88)\
**Post date:** [December 10, 2021, 4:48am UTC](https://discourse.threejs.org/t/root-skeleton-getbonebyname-is-not-a-function/32538/1 "2021-12-10T04:48:44Z")

</div>

When using clipAction on a cloned animation fbx on a cloned character model, I get the following error:

```javascript
Uncaught (in promise) TypeError: root.skeleton.getBoneByName is not a function
    at Function.findNode (three.js:31518)
    at new PropertyBinding (three.js:31447)
    at Function.create (three.js:31456)
    at AnimationMixer._bindAction (three.js:32670)
    at AnimationMixer.clipAction (three.js:33007)

```

After console.log the characterModel, there seemed to be no issues in the object, it looked like a normal Group, so what is causing this error?

Here is the clone method brought from here: [Clone an already-loaded FBX model in three.js and be able to animate it. Adapted from: https://gist.github.com/cdata/f2d7a6ccdec071839bc1954c32595e87 · GitHub](https://gist.github.com/kevincharm/bf12a2c673b43a3988f0f171a05794c1)

```javascript
const cloneFbx = (fbx) => {
  const clone = fbx.clone(true)
  clone.animations = fbx.animations
  clone.skeleton = { bones: [] }

  const skinnedMeshes = {}

  fbx.traverse(node => {
      if (node.isSkinnedMesh) {
          skinnedMeshes[node.name] = node
      }
  })

  const cloneBones = {}
  const cloneSkinnedMeshes = {}

  clone.traverse(node => {
      if (node.isBone) {
          cloneBones[node.name] = node
      }

      if (node.isSkinnedMesh) {
          cloneSkinnedMeshes[node.name] = node
      }
  })

  for (let name in skinnedMeshes) {
      const skinnedMesh = skinnedMeshes[name]
      const skeleton = skinnedMesh.skeleton
      const cloneSkinnedMesh = cloneSkinnedMeshes[name]

      const orderedCloneBones = []

      for (let i=0; i<skeleton.bones.length; i++) {
          const cloneBone = cloneBones[skeleton.bones[i].name]
          orderedCloneBones.push(cloneBone)
      }

      cloneSkinnedMesh.bind(
          new THREE.Skeleton(orderedCloneBones, skeleton.boneInverses),
          cloneSkinnedMesh.matrixWorld)

      // For animation to work correctly:
      clone.skeleton.bones.push(cloneSkinnedMesh)
      clone.skeleton.bones.push(...orderedCloneBones)
  }

  return clone
}

```

and the code causing the error

```javascript
const characterModel = cloneFbx(characterModelRaw);
const deathAnimation = cloneFbx(animationFBXs["death.fbx"]);
const deathAnimationMixer = new THREE.AnimationMixer(characterModel);
const death = deathAnimationMixer.clipAction(deathAnimation.animations[0]);

```

`animationFBXs` is an object mapping the name of the animation to the imported FBX file of the animation. And `characterModelRaw` is an imported character model.

---

<div class="post-metadata">

**Author:** ![0x88](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/0x88/32/20992_2.png) [@0x88](https://discourse.threejs.org/u/0x88)\
**Post date:** [December 11, 2021, 5:53am UTC](https://discourse.threejs.org/t/root-skeleton-getbonebyname-is-not-a-function/32538/2 "2021-12-11T05:53:55Z")

</div>

Replace the `cloneFbx` with a new `cloneFbx` method. The one I initially used seems to be outdated (made in 2017).  
The `clone` method is imported from [https://threejs.org/examples/jsm/utils/SkeletonUtils.js](https://threejs.org/examples/jsm/utils/SkeletonUtils.js).

```javascript
import {clone} from "https://threejs.org/examples/jsm/utils/SkeletonUtils.js"

function cloneFbx(fbx) {
  const fbxClone = clone(fbx);
  fbxClone.animations = fbx.animations;
  return fbxClone;
}; 

```
