# SAnimation

## Index

### Functions Index

| Function Name                                                                                                                                                      |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p>SAnimationState <a href="#getstate"><strong>GetState</strong> </a>()</p><p>SAnimationState <a href="#getstate"><strong>GetState</strong> </a>(string state)</p> |
| void [**Blend** ](#blend)(string animation, float targetWeight=1.0F, float fadeLength=0.3F)                                                                        |
| void [**CrossFade** ](#crossfade)(string animation, float fadeLength=0.3F)                                                                                         |
| SAnimationState [**CrossFadeQueued** ](#crossfadequeued)(string animation, float fadeLength=0.3F, bool playNow=false)                                              |
| int [**GetClipCount** ](#getclipcount)()                                                                                                                           |
| bool [**IsPlaying** ](#isplaying)(string animation)                                                                                                                |
| <p>bool <a href="#play"><strong>Play</strong> </a>()</p><p>bool <a href="#play"><strong>Play</strong> </a>(string animation)</p>                                   |
| SAnimationState [**PlayQueued** ](#playqueued)(string animation, bool playNow=false)                                                                               |
| void [**Rewind** ](#rewind)(string animation)                                                                                                                      |
| void [**Sample** ](#sample)()                                                                                                                                      |
| <p>void <a href="#stop"><strong>Stop</strong> </a>()</p><p>void <a href="#stop"><strong>Stop</strong> </a>(string animation)</p>                                   |

### Properties Index

| Property Name                                                      |
| ------------------------------------------------------------------ |
| bool [**Enabled** ](#enabled)`get` `set`                           |
| IDictionary< string, SAnimationState > [**States** ](#states)`get` |

## Functions

### GetState

[SAnimationState](https://docs.sine.space/scripting/client-scripting-api-reference/types/sanimationstate) **GetState** () \
[SAnimationState](https://docs.sine.space/scripting/client-scripting-api-reference/types/sanimationstate) **GetState** (string state)

*Returns the SAnimationState for the default animation clip.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
State = Space.Host.ExecutingObject.Animation.GetState()
State = Space.Host.ExecutingObject.Animation.GetState("statename")
```

{% endtab %}
{% endtabs %}

### Blend

void **Blend** (string animation, float targetWeight=1.0F, float fadeLength=0.3F)

*Blends the animation named animation towards targetWeight over the next time seconds. Playback of other animations will not be affected.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Animation.Blend("animationname",1.0,0.3)
```

{% endtab %}
{% endtabs %}

### CrossFade

void **CrossFade** (string animation, float fadeLength=0.3F)

*Fades the animation with name animation in over a period of time seconds and fades other animations out.*

*If mode is PlayMode.StopSameLayer, animations in the same layer as animation will be faded out while animation is faded in. if mode is PlayMode.StopAll, all animations will be faded out while animation is faded in.*

*If the animation is not set to be looping it will be stopped and rewound after playing.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Animation.CrossFade("animationname", 0.3)
```

{% endtab %}
{% endtabs %}

### CrossFadeQueued

[SAnimationState](https://docs.sine.space/scripting/client-scripting-api-reference/types/sanimationstate) **CrossFadeQueued** (string animation, float fadeLength=0.3F, bool playNow=false)

*Returns a duplicated SAnimationState. This duplicate will self-destruct after it is finished playing. Referencing it after it has completed will result in an error.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
NewSAnimationState = Space.Host.ExecutingObject.Animation.CrossFadeQueued("animationname", 0.3, false)
```

{% endtab %}
{% endtabs %}

### GetClipCount

int **GetClipCount** ()

*Get the number of clips currently assigned to this animation.*

{% tabs %}
{% tab title="Lua" %}

```lua
NumberOfClips = Space.Host.ExecutingObject.Animation.GetClipCount() 
```

{% endtab %}
{% endtabs %}

### IsPlaying

bool **IsPlaying** (string animation)

*Is the animation named name playing?*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
IsPlaying = Space.Host.ExecutingObject.Animation.IsPlaying("animationname")
```

{% endtab %}
{% endtabs %}

### Play

bool **Play** () bool **Play** (string animation)

*Plays an animation without any blending.*

*If no name is supplied then the default animation will be played. In cases where the animation can't be played (ie, there is no default animation or no animation with the specified name), the function will return false.*

*The optional playMode lets you choose how this animation will affect others already playing.*

*If the specified animation is already playing then other animations will be stopped but the animation will not rewind to the beginning.*

*When the end of the animation is reached it will automatically be stopped and rewound to the start unless the PlayMode is set to Loop.*

*Note that if you call Animation.Play on an object during a frame update where the object is also deactivated then the call will effectively be cancelled; the animation will not start playing when the object is later reactivated. However, if you make the call on a subsequent frame (ie, while the object is still inactive) then the animation will start playing after reactivation.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Animation.Play()
Space.Host.ExecutingObject.Animation.Play("animationname")
```

{% endtab %}
{% endtabs %}

### PlayQueued

[SAnimationState](https://docs.sine.space/scripting/client-scripting-api-reference/types/sanimationstate) **PlayQueued** (string animation, bool playNow=false)

*Returns a duplicated SAnimationState. This duplicate will self-destruct after it is finished playing. Referencing it after it has completed will result in an error.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Animation.PlayQueued("animationname","false")
```

{% endtab %}
{% endtabs %}

### Rewind

void **Rewind** (string animation)

*Rewinds the animation named name.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Animation.Rewind()
```

{% endtab %}
{% endtabs %}

### Sample

void **Sample** ()

*Samples animations at the current state.*

*This is useful when you explicitly want to set up some animation state, and sample it once.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Animation.Sample()
```

{% endtab %}
{% endtabs %}

### Stop

void **Stop** () \
void **Stop** (string animation)

*Stops all playing animations that were started with this Animation.*

*Stopping an animation also Rewinds it to the Start.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Animation.Stop()
Space.Host.ExecutingObject.Animation.Stop("animationname")
```

{% endtab %}
{% endtabs %}

## Properties

### Enabled

bool **Enabled** `get` `set`

Whether this component is enabled or not.

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Animation.Enabled = false
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--clicking this object will Enable/Disable it's Animation component
thisGameObject = Space.Host.ExecutingObject
animation = thisGameObject.Animation


OnClick = function()
animation.Enabled =  not animation.Enabled
end

thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### States

IDictionary< string, [SAnimationState](https://docs.sine.space/scripting/client-scripting-api-reference/types/sanimationstate) > **States** `get`

*Returns a table of* [*SAnimationState*](https://docs.sine.space/scripting/client-scripting-api-reference/types/sanimationstate) *names and references*

{% tabs %}
{% tab title="Lua" %}

```lua
States = Space.Host.ExecutingObject.Animation.States
```

{% endtab %}
{% endtabs %}

### GameObject

[SGameObject](https://docs.sine.space/scripting/client-scripting-api-reference/types/sgameobject) **GameObject** `get`

*Returns a reference to the GameObject of this component.*

{% tabs %}
{% tab title="Lua" %}

```lua
theGameObject = Space.Host.ExecutingObject.Animation.GameObject
```

{% endtab %}
{% endtabs %}
