<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/AnimationLibraryComponent",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation25AnimationLibraryComponentV"
  },
  "title" : "AnimationLibraryComponent"
}
-->

# AnimationLibraryComponent

A component that represents a collection of animations that an entity can play.

```
struct AnimationLibraryComponent
```

## Overview

You use an `AnimationLibraryComponent` to access an entity’s animation resources.
You can store animations with an entity by packaging them together into a `.reality` file.
You can do this with Reality Composer Pro or by building a custom tool.

### Create an animation library with Reality Composer Pro

Follow these steps to create an animation library for an entity:

1. In the hierarchy view, select the entity you want to add animations to.
2. In the inspector, click Add Component and select Animation Library from the list of components.
3. Click the Add button (+) and select the USD files with animations.

![A screenshot of Reality Composer Pro showing the Animation Library in the Inspector. It contains two elements representing animations that have been added to the animation library. The animations are named walk and idle.](images/com.apple.RealityKit/realitycomposerpro-animationlibrary)

At runtime, your app can access and play the animations that the entity stores.

```swift
// Load the entity you want to animate.
let robot = try await Entity(named: "robot")

// Access the animation library associated with the entity.
let animationLibrary = robot.components[AnimationLibraryComponent.self]

// Play the walk animation.
if let walkAnimation = animationLibrary.animations["walk"] {
    robot.playAnimation(walkAnimation)
}
```

### Create an animation library by building your own tool

If you need to build a custom tool to create `.reality` files, you can use RealityKit to programmatically
create an animation library by following these steps:

1. Load an animation entity with [`init(named:in:)`](/documentation/RealityKit/Entity/init(named:in:)).
2. Retrieve the entity’s animation resources from its [`availableAnimations`](/documentation/RealityKit/Entity/availableAnimations) property.
3. Add the animations to an animation library.

The following example shows how you can set up an animation library:

```swift
// Create an empty animation library component.
var animationLibrary = AnimationLibraryComponent()

// Load the entities containing the animations.
let entityIdleAnimation = try await Entity(named: "idle")
let entityWalkAnimation = try await Entity(named: "walk")

// Assign the animations to the library by name.
animationLibrary.animations["idle"] = entityIdleAnimation.availableAnimations.first
animationLibrary.animations["walk"] = entityWalkAnimation.availableAnimations.first
```

After you configure the animation library, you can assign it to an entity and serialize the entity to a file.
RealityKit packages the animations for that entity when you save it to a `.reality` file.

```swift
// Load the entity you want to animate.
let robot = try! await Entity(named: "robot")

// Assign the animation library to the entity.
robot.components.set(animationLibrary)

// Write the entity with its animations to a file.
robot.write(to: fileURL)
```

To play one of the animations in your app, create an entity
from the `.reality` file and then call its [`playAnimation(_:transitionDuration:startsPaused:)`](/documentation/RealityKit/Entity/playAnimation(_:transitionDuration:startsPaused:)) method.

## Topics

### Creating an animation library component

[`init()`](/documentation/RealityKit/AnimationLibraryComponent/init())

Creates an empty animation library.

[`init(animations:)`](/documentation/RealityKit/AnimationLibraryComponent/init(animations:))

Creates an animation library from a dictionary that associates an animation’s data with its name.

[`init(dictionaryLiteral:)`](/documentation/RealityKit/AnimationLibraryComponent/init(dictionaryLiteral:))

Creates an animation library from a variadic list of key-value pairs.

### Accessing animations

[`animations`](/documentation/RealityKit/AnimationLibraryComponent/animations)

The collection of animations an entity can play.

[`unkeyedResources`](/documentation/RealityKit/AnimationLibraryComponent/unkeyedResources)

The library’s animation resources that don’t have a queryable name.

[`defaultAnimation`](/documentation/RealityKit/AnimationLibraryComponent/defaultAnimation)

The default animation resource.

[`defaultKey`](/documentation/RealityKit/AnimationLibraryComponent/defaultKey)

The name of the default animation resource.

### Managing references to animations

[`removeAll(resource:)`](/documentation/RealityKit/AnimationLibraryComponent/removeAll(resource:))

Removes all the component’s references to an animation resource.

### Configuring default playback

[`automaticallyPlaysDefaultAnimation`](/documentation/RealityKit/AnimationLibraryComponent/automaticallyPlaysDefaultAnimation)

Whether to automatically play the default animation when the entity is added to a scene and enabled.
Default value is false, meaning the default animation will not be automatically played by default. This
value can only be set when initializing `AnimationLibraryComponent`

[`init(automaticallyPlaysDefaultAnimation:)`](/documentation/RealityKit/AnimationLibraryComponent/init(automaticallyPlaysDefaultAnimation:))

Creates an empty animation library.

[`init(animations:automaticallyPlaysDefaultAnimation:)`](/documentation/RealityKit/AnimationLibraryComponent/init(animations:automaticallyPlaysDefaultAnimation:))

Creates an animation library from a dictionary that associates an animation’s data with its name.

## Relationships

### Conforms To

[`Component`](/documentation/RealityKit/Component)

[`ExpressibleByDictionaryLiteral`](/documentation/Swift/ExpressibleByDictionaryLiteral)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)