# AnimationComponent

Kind: Class · Namespace: Sansar.Simulation · Assembly: Sansar.Simulation.dll · Script API 47.10.0

<div class="api-meta">
<span class="api-kind api-kind-class" data-pagefind-filter="kind:Class">Class</span>
<span data-pagefind-filter="namespace:Sansar.Simulation">Namespace <a href="/scripting/api/sansar.simulation"><code>Sansar.Simulation</code></a></span>
<span>Inherits <a href="/scripting/api/sansar.script/instanceinterface">Sansar.Script.InstanceInterface</a></span>
</div>

<span id="T:Sansar.Simulation.AnimationComponent"></span>

The AnimationComponent handles interactions with animations.

```csharp
public class AnimationComponent : Sansar.Script.InstanceInterface
```

## Remarks

Animated objects should be manipulated through this interface.

## Members at a glance

| Kind | Members |
|---|---|
| **Fields** | [ComponentType](#componenttype) |
| **Properties** | [ComponentId](#componentid) · [DefaultAnimation](#defaultanimation) · [Name](#name) |
| **Methods** | [EnqueueEvent](#enqueueevent) · [GetAnimation](#getanimation) · [GetAnimations](#getanimations) · [GetEventId](#geteventid) · [GetVectorAnimationVariable](#getvectoranimationvariable) · [HasEvent](#hasevent) · [SetPosition](#setposition) · [Subscribe](#subscribe) · [ToString](#tostring) |

## Fields

### ComponentType

<div class="api-card">
<span id="F:Sansar.Simulation.AnimationComponent.ComponentType"></span>

```csharp signature
public static readonly ComponentType ComponentType
```

The [`AnimationComponent.ComponentType`](/scripting/api/sansar.simulation/animationcomponent#componenttype) of this component

</div>


## Properties

### ComponentId

<div class="api-card">
<span id="P:Sansar.Simulation.AnimationComponent.ComponentId"></span>

```csharp signature
public Sansar.Script.ComponentId ComponentId { get; }
```

Retrieves the component id for this AnimationComponent.

**Value:** [Sansar.Script.ComponentId](/scripting/api/sansar.script/componentid) — The id.

<details class="api-remarks"><summary>Remarks</summary>

This id will be unique among all components.

</details>

</div>

### DefaultAnimation

<div class="api-card">
<span id="P:Sansar.Simulation.AnimationComponent.DefaultAnimation"></span>

```csharp signature
public Animation DefaultAnimation { get; }
```

Gets the default scriptable animation.

**Value:** [Animation](/scripting/api/sansar.simulation/animation) — An Animation object.

</div>

### Name

<div class="api-card">
<span id="P:Sansar.Simulation.AnimationComponent.Name"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 33.2.0</span></div>

```csharp signature
public string Name { get; }
```

This AnimationComponent name, as specified in the editor.

</div>


## Methods

### EnqueueEvent

<div class="api-card" id="enqueueevent-int32">
<span id="M:Sansar.Simulation.AnimationComponent.EnqueueEvent(System.Int32)"></span>

```csharp signature
public void EnqueueEvent(int internalId)
```

Enqueues an event for this component.

| Parameter | Type | Description |
|---|---|---|
| `internalId` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | The id of the animation event, may be looked up by name from [`AnimationComponent.GetEventId`](/scripting/api/sansar.simulation/animationcomponent#geteventid) |

<details class="api-remarks"><summary>Remarks</summary>

Ids can be retrieved with [`AnimationComponent.GetEventId`](/scripting/api/sansar.simulation/animationcomponent#geteventid).

</details>

</div>

<div class="api-card" id="enqueueevent-int32-operationcomplete">
<span id="M:Sansar.Simulation.AnimationComponent.EnqueueEvent(System.Int32,Sansar.Script.ScriptBase.OperationComplete)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Deprecated. Use the Action<> overload", false)]
public ulong EnqueueEvent(
    int internalId,
    Sansar.Script.ScriptBase.OperationComplete handler
)
```

Enqueues an event for this component.

| Parameter | Type | Description |
|---|---|---|
| `internalId` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | The id of the animation event, may be looked up by name from [`AnimationComponent.GetEventId`](/scripting/api/sansar.simulation/animationcomponent#geteventid) |
| `handler` | [Sansar.Script.ScriptBase.OperationComplete](/scripting/api/sansar.script/scriptbase.operationcomplete) | Handler to be called when the event completes. |

**Returns:** [ulong](https://learn.microsoft.com/dotnet/api/system.uint64) — The internal event id for the completion event.

<details class="api-remarks"><summary>Remarks</summary>

Ids can be retrieved with [`AnimationComponent.GetEventId`](/scripting/api/sansar.simulation/animationcomponent#geteventid).

</details>

</div>

<div class="api-card" id="enqueueevent-int32-action">
<span id="M:Sansar.Simulation.AnimationComponent.EnqueueEvent(System.Int32,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void EnqueueEvent(
    int internalId,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Enqueues an event for this component.

| Parameter | Type | Description |
|---|---|---|
| `internalId` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | The id of the animation event, may be looked up by name from [`AnimationComponent.GetEventId`](/scripting/api/sansar.simulation/animationcomponent#geteventid) |
| `handler` | [Action&lt;Sansar.Script.OperationCompleteEvent&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Handler to be called when the event completes. |

<details class="api-remarks"><summary>Remarks</summary>

Ids can be retrieved with [`AnimationComponent.GetEventId`](/scripting/api/sansar.simulation/animationcomponent#geteventid).

</details>

</div>

### GetAnimation

<div class="api-card">
<span id="M:Sansar.Simulation.AnimationComponent.GetAnimation(System.String)"></span>

```csharp signature
public Animation GetAnimation(string animationName)
```

Finds a scriptable animations by name.

| Parameter | Type | Description |
|---|---|---|
| `animationName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The name of the animation. |

**Returns:** [Animation](/scripting/api/sansar.simulation/animation) — An Animation, or null if no animation was found with the correct name.

</div>

### GetAnimations

<div class="api-card">
<span id="M:Sansar.Simulation.AnimationComponent.GetAnimations"></span>
<span id="M:Sansar.Simulation.AnimationComponent.GetAnimations()"></span>

```csharp signature
public IEnumerable<Animation> GetAnimations()
```

Gets the scriptable animations for this object.

**Returns:** [IEnumerable&lt;Animation&gt;](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) — An IEnumarable collection of animation objects.

</div>

### GetEventId

<div class="api-card">
<span id="M:Sansar.Simulation.AnimationComponent.GetEventId(System.String)"></span>

```csharp signature
public int GetEventId(string eventName)
```

Lookup the event id for the named event.

| Parameter | Type | Description |
|---|---|---|
| `eventName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The name of the event to query. |

**Returns:** [int](https://learn.microsoft.com/dotnet/api/system.int32) — The id of the named event or -1 if the name is not valid.

<details class="api-remarks"><summary>Remarks</summary>

This can be used to trigger animations with [`AnimationComponent.EnqueueEvent`](/scripting/api/sansar.simulation/animationcomponent#enqueueevent-int32).

</details>

</div>

### GetVectorAnimationVariable

<div class="api-card">
<span id="M:Sansar.Simulation.AnimationComponent.GetVectorAnimationVariable(System.String)"></span>

```csharp signature
public Sansar.Vector GetVectorAnimationVariable(string variableName)
```

Get a Vector type variable from the animation by name

| Parameter | Type | Description |
|---|---|---|
| `variableName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The name of the animation variable |

**Returns:** [Sansar.Vector](/scripting/api/sansar/vector) — A Mono.Simd.Vector4f of the value of the named variable

**Throws** [`ArgumentException`](https://learn.microsoft.com/dotnet/api/system.argumentexception): Thrown when attempting to get a variable that doesn&#39;t exist or is of the wrong type

**Throws** [`ArgumentNullException`](https://learn.microsoft.com/dotnet/api/system.argumentnullexception): If variableName is null

<details class="api-remarks"><summary>Remarks</summary>

Characters have an &#39;LLCameraForward&#39; variable which can be queried with GetVectorAnimationVariable to determine the forward vector of the camera.

</details>

</div>

### HasEvent

<div class="api-card">
<span id="M:Sansar.Simulation.AnimationComponent.HasEvent(System.String)"></span>

```csharp signature
public bool HasEvent(string eventName)
```

Check this component for the existence of the named event.

| Parameter | Type | Description |
|---|---|---|
| `eventName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The name of the event to query. |

**Returns:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean) — true if the event exits.

<details class="api-remarks"><summary>Remarks</summary>

Can be used to check if an event exists.

</details>

</div>

### SetPosition

<div class="api-card" id="setposition-vector">
<span id="M:Sansar.Simulation.AnimationComponent.SetPosition(Sansar.Vector)"></span>

```csharp signature
public void SetPosition(Sansar.Vector position)
```

Asynchronously set the position for this object.

| Parameter | Type | Description |
|---|---|---|
| `position` | [Sansar.Vector](/scripting/api/sansar/vector) | The Mono.Simd.Vector4f position desired. |

<details class="api-remarks"><summary>Remarks</summary>

To block until the method returns pass this to [`ScriptBase.WaitFor`](/scripting/api/sansar.script/scriptbase#waitfor-func-2) in a coroutine.

</details>

</div>

<div class="api-card" id="setposition-vector-operationcomplete">
<span id="M:Sansar.Simulation.AnimationComponent.SetPosition(Sansar.Vector,Sansar.Script.ScriptBase.OperationComplete)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Deprecated. Use the Action<> overload", false)]
public ulong SetPosition(
    Sansar.Vector position,
    Sansar.Script.ScriptBase.OperationComplete handler
)
```

Asynchronously set the position for this object.

| Parameter | Type | Description |
|---|---|---|
| `position` | [Sansar.Vector](/scripting/api/sansar/vector) | The Mono.Simd.Vector4f position desired. |
| `handler` | [Sansar.Script.ScriptBase.OperationComplete](/scripting/api/sansar.script/scriptbase.operationcomplete) | Handler to be called when the event completes. |

**Returns:** [ulong](https://learn.microsoft.com/dotnet/api/system.uint64) — Returns an internal event id.

<details class="api-remarks"><summary>Remarks</summary>

To block until the method returns pass this to [`ScriptBase.WaitFor`](/scripting/api/sansar.script/scriptbase#waitfor-func-2) in a coroutine.

</details>

</div>

<div class="api-card" id="setposition-vector-action">
<span id="M:Sansar.Simulation.AnimationComponent.SetPosition(Sansar.Vector,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void SetPosition(
    Sansar.Vector position,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Asynchronously set the position for this object.

| Parameter | Type | Description |
|---|---|---|
| `position` | [Sansar.Vector](/scripting/api/sansar/vector) | The Mono.Simd.Vector4f position desired. |
| `handler` | [Action&lt;Sansar.Script.OperationCompleteEvent&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Handler to be called when the event completes. |

<details class="api-remarks"><summary>Remarks</summary>

To block until the method returns pass this to [`ScriptBase.WaitFor`](/scripting/api/sansar.script/scriptbase#waitfor-func-2) in a coroutine.

</details>

</div>

### Subscribe

<div class="api-card" id="subscribe-string-subscriptionhandler-boolean">
<span id="M:Sansar.Simulation.AnimationComponent.Subscribe(System.String,Sansar.Simulation.AnimationComponent.SubscriptionHandler,System.Boolean)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Use subscription callbacks of type Action<Sansar.Simulation.AnimationData>", true)]
public void Subscribe(
    string BehaviorName,
    AnimationComponent.SubscriptionHandler callback,
    bool persistent
)
```

Subscribes to Animation Events.

| Parameter | Type | Description |
|---|---|---|
| `BehaviorName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The behavior name of the Animation. This name will match the subscribed event. |
| `callback` | [AnimationComponent.SubscriptionHandler](/scripting/api/sansar.simulation/animationcomponent.subscriptionhandler) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

</div>

<div class="api-card" id="subscribe-string-action-boolean">
<span id="M:Sansar.Simulation.AnimationComponent.Subscribe(System.String,System.Action{Sansar.Simulation.AnimationData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    string BehaviorName,
    Action<AnimationData> callback,
    bool persistent
)
```

Subscribes to Animation Events.

| Parameter | Type | Description |
|---|---|---|
| `BehaviorName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The behavior name of the Animation. This name will match the subscribed event. |
| `callback` | [Action&lt;AnimationData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

### ToString

<div class="api-card">
<span id="M:Sansar.Simulation.AnimationComponent.ToString"></span>
<span id="M:Sansar.Simulation.AnimationComponent.ToString()"></span>

```csharp signature
public override string ToString()
```

A string representation of this object.

**Returns:** [string](https://learn.microsoft.com/dotnet/api/system.string) — A string representation of this object.

<details class="api-remarks"><summary>Remarks</summary>

The format of this string may change between releases.

</details>

</div>


## Used in examples

- [FollowThePath.cs](/scripting/examples/follow-the-path)
- [AnimationExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/AnimationExample.cs)
- [ScriptLibrary/Scene/Animation.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Scene/Animation.cs)

<p class="api-generated" data-pagefind-ignore>Generated from the Sansar 47.10.0 client ScriptApi snapshot.</p>