Animations bugging out on updating children parts of a model

Hello, I’m trying to build a kind of a model configurator mini game in react three fiber where users can remove individual children parts of a model, and reattach them back. These removal of parts are followed by animations followed by these parts being set at some final positions. Although the animations play fine the first time around, any changes to the individual children parts like changing their positions, or removing them and setting them at a different position, make the animation non-playable if tried again after reattaching them back. I am unable to figure out what the issue may be. Any help would be appreciated.

Here’s how I load animations:

 useEffect(() => {
        if (gltf) {
            const model = gltf.scene;
            modelRef.current = model;
            const mixer = new THREE.AnimationMixer(model);
            model.traverse((child) => {
                if (child.isMesh) {
                    child.castShadow = true;
                    child.receiveShadow = true;

            // Once everything is set
    }, [gltf, scene]);

    return { modelRef, gltf, animationMixer, isLoaded };

These are passed to another component where animations are played out like this:

 if (animationType === 'removalAnimation') {
            if (partData && animationMixer) {
                const animationData = partData[animationType];
                const clip = THREE.AnimationClip.findByName(clips,;
                if (clip) {
                    const action = animationMixer.clipAction(clip);
                    if (action) {
                        action.clampWhenFinished = true;
                        if (!partData.Combined){
                            console.log("Action is: ",action)
                       const keyframeStart = animationData.keyframes.start / clip.tracks[0].times.length * clip.duration;
                        const keyframeEnd = animationData.keyframes.end / clip.tracks[0].times.length * clip.duration;
                        const playDuration = keyframeEnd - keyframeStart;
                        action.time = keyframeStart;
                        let elapsedTime = 0;
                        captureDefaultTransforms(modelData.modelName, partName)
                        const interval = setInterval(() => {
                            elapsedTime += 0.016; // Assume 60 fps
                            if (elapsedTime >= playDuration - 0.016) {
                                        if (partMesh && partData && partData.finalState) {
                                    const worldPosition = new THREE.Vector3();
                                    const worldQuaternion = new THREE.Quaternion();
                                    const worldScale = new THREE.Vector3();


                                    // Detach the partMesh from its parent and add it to the scene
                                    // Set its world position, rotation, and scale (preserving its world transform)
                                    // Tween to the final state
                                    new TWEEN.Tween(partMesh.position)
                                        .to(partData.finalState.position, 1000)

                                    new TWEEN.Tween(partMesh.quaternion)
                                        .to(partData.finalState.rotation, 1000)

                                    new TWEEN.Tween(partMesh.scale)
                                        .to(partData.finalState.scale, 1000)
                            if (elapsedTime >= playDuration) {
                        }, 16);
                    } else {
                        console.error(`Animation clip not found: ${}`);
                } else {
                    console.error(`Part data not found: ${partName} or AnimationMixer not defined.`);

You can see how parts are being removed after playing the animations after certain frames. The issue is that after removal, the animations don’t playout as expected on attaching the parts back. This is how I add the parts back to the model:

if (part) {
            if (!modelRef.current.getObjectByName( {
              const { position, rotation, scale } = partData.defaultTransform;
              part.position.set(position.x, position.y, position.z);
              part.quaternion.set(rotation.x, rotation.y, rotation.z, rotation.w);
              part.scale.set(scale.x, scale.y, scale.z);

The part in this are all meshes stored before of the parts that were removed. So, basically, after adding the parts back and triggering the animations, they don’t play and the part generally shifts to the final position without animations.