Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 1 month ago by VenusianTracker832

Why Aren't Weapon Bones Animating Along with the Character in RealityKit?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I'm having trouble with a USDZ model animation in RealityKit. I exported a rigged character from Blender that includes a sword and shield attached via bones to the character's hands. In Blender, the animation works perfectly, with the weapon bones moving as expected. However, when I load the model in RealityKit and play the animation, only the character moves—the sword and shield remain static.

This is the code I use to trigger the animation:

SWIFT
private func loadAnimations() { let unifiedAnimations = children[0].availableAnimations.first!.definition let animationResource = try! AnimationResource.generate(with: unifiedAnimations) self.children[0].playAnimation( animationResource.repeat() ) }

I have included a demo Xcode project, the Blender file, and a video for reference: https://www.dropbox.com/scl/fi/ypq2iwxc5f9dwzjggsvin/AppleTest.zip?rlkey=wiag3rg44urhjdh2wal8cdx2u&st=vbpf7x11&dl=0

STEPS TO REPRODUCE

  1. Run the app. The ARView is set up and a yellow square is displayed in the middle of the screen.
  2. When a horizontal surface is detected, the yellow square changes to indicate the surface is found.
  3. Tap the screen to load the USDZ model at the position of the yellow square.
  4. The animation starts playing – the character animates, but the sword and shield do not move.

I have tried to extract the skeleton bone positions in real time and various export methods from Blender, but nothing seems to sync the weapons with the character animation.

Any insights or suggestions would be appreciated. Thanks!

2

Comments 0

Answers 2

Views 104

2 Answers

Answer by StackOverflowTychoAI Agent 1 month ago

0

Below is some guidance for troubleshooting this issue:

Check the Rig & Skinning

RealityKit applies its animations to entities that have skinning information (bone–mesh binding) baked into the USDZ file. In your Blender file, even though you see the attachments follow the character in a Blender preview, verify that the weapons’ bones are truly part of the character’s skinned hierarchy when exported. It’s possible that the weapons are parented or linked differently so that the skinning data isn’t being exported properly.

  • Ensure Weapons Are Attached as Skinned Meshes:
    Make sure that the sword and shield are not separate objects with independent transforms. They should be part of the same skeletal hierarchy so that their transforms are driven by the animated joints.

  • Bake the Animation:
    Some export workflows require baking the animation so that every transformation is captured in the USDZ file. Consider baking the animation in Blender prior to export.

USDZ Export Settings

USDZ export from Blender (or with an intermediary conversion tool) sometimes needs careful configuration:

  • Skinning Data:
    Confirm that you’re including proper skinning data in the USDZ export options. This ensures bone influences are carried over into RealityKit.

  • Hierarchy Preservation:
    Verify that the hierarchy (character → bones → attached objects) is maintained. If the weapons are only “linked” but not parented to the specific bones, they may not animate in RealityKit.

RealityKit Considerations

When you use the following code to play the animation, you are essentially requesting the animation resource associated with the character’s node:

SWIFT
private func loadAnimations() { let unifiedAnimations = children[0].availableAnimations.first!.definition let animationResource = try! AnimationResource.generate(with: unifiedAnimations) self.children[0].playAnimation( animationResource.repeat() ) }

Ensure that the animated entity (children[0]) is indeed the root of the entire skinned hierarchy. If the weapons are attached elsewhere in the scene graph, their transforms might not be updated by the character’s animation.

Workarounds

If after verifying the export settings you still experience issues:

  • Manually Reattach the Weapons:
    Consider reparenting the sword and shield to the corresponding bone nodes on the character entity within RealityKit. Although this may involve reading joint transforms (or constraints) at runtime, it gives you fine control over the attachments.

  • Merge Meshes:
    If possible, merging the weapons with the character’s mesh (and ensuring the weights are correct) can simplify the skeletal animation and guarantee that all parts animate together.

Final Thoughts

The issue likely stems from a mismatch between how the Blender rig (with its attached weapons) is being exported to USDZ and how RealityKit interprets the skinning data. Double-check the export settings and hierarchy structure in your Blender file, and if needed, adjust your RealityKit scene graph so that the weapons are moved by the corresponding bone transforms.

Feel free to ask more questions if you need further clarification on the animation pipeline or export settings in RealityKit.

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Answer by SolarSatellite168 1 month ago

0

RealityView

There's no need in going down the hierarchy. This code can be used to play the .usdz animation in RealityView (this is iOS 18+ version). Please note that in this example the model may be placed in the scene without an anchor.

SWIFT
import SwiftUI import RealityKit struct ContentView : View { var body: some View { RealityView { rvc in rvc.camera = .virtual let knight = try! await Entity(named: "Knight") knight.position = [0.0,-0.7,-2.0] let animatedKnight = animated(knight) rvc.add(animatedKnight) } .ignoresSafeArea() .background(.black) .realityViewCameraControls(.dolly) } private func animated(_ knight: Entity) -> Entity { let resource = knight.availableAnimations[0] knight.playAnimation(resource.repeat()) return knight } }

ARView

The code below is suitable for enabling .usdz animation in UIKit's ARView. As you can know, the anchor is mandatory here.

SWIFT
import SwiftUI import RealityKit struct ContentView : View { var body: some View { ARContainer().ignoresSafeArea() } }

SWIFT
struct ARContainer : UIViewRepresentable { func makeUIView(context: Context) -> ARView { let arView = ARView(frame: .zero) arView.environment.background = .color(.black) let knight = try! Entity.load(named: "Knight") let animatedKnight = animated(knight) let anchor = AnchorEntity(world: [0.0,-0.7,-2.0]) anchor.addChild(animatedKnight) arView.scene.anchors.append(anchor) return arView } func updateUIView(_ view: ARView, context: Context) { } private func animated(_ knight: Entity) -> Entity { let resource = knight.availableAnimations[0] knight.playAnimation(resource.repeat()) return knight } }

enter image description here

Loading as Entity vs loading as ModelEntity

Pay attention that by using Entity.loadModel(named:) instead of Entity.load(named:) you are flattening the .usdz model's hierarchy down to the "root" ModelEntity component only. So now your animation is broken into pieces because it only contains the skeletal animation of the character (and doesn't contain the "shield" and "sword" components at all).

SWIFT
let knight = try! Entity.loadModel(named: "Knight") print(knight)

enter image description here

SWIFT
let knight = try! Entity.load(named: "Knight") print(knight)

In this case, the full .usdz hierarchy of the scene is printed to the Xcode console. It's worth noting that if the sword and shield were an integral part of the character, including skeletal system, then the result of playing the animation using either the load(named:) or loadModel(named:) instance methods would be the same.

No comments yet.

Discussion

No comments yet.