# States

## Overview

States are the core logic for the Animal to work. They make the animal move, fall, jump, die, etc.

States are animations that do not overlap each other. For example: the animal cannot be running and jumping at the same time, or Flying and swimming.

They are also sorted by priority, meaning that higher Priority States will try to activate first, followed by the lower priority ones.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FG3MJh5nvGpNp0BPBxUN3%2Fimage.png?alt=media&#x26;token=b342e16b-46c8-4ead-9e50-8c970631884e" alt="" width="467"><figcaption></figcaption></figure>

{% hint style="info" %}
If a Higher Priority State is the **Active** State: Lower states won't try to activate unless the  Active State allows it. Using **`State.AllowExit()`**&#x77;ill permit again the lower states a chance to activate themselves.&#x20;

That is why when the Animal is on the Fly state; all the Lower states like Fall, Swim or Jump wont be activated unless the Fly State **AllowExit()** is called.
{% endhint %}

## Override Start State

Starts the Animal Controller in a custom State instead of initializing in \[Idle].

If you want the animal to start with the **Fly State** then set the **Fly ID** there

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FhZd3Y51uTd9LJ3CKvoov%2FUnity_GO7qcQysrm.gif?alt=media&#x26;token=fd4aea2b-5c87-492a-9620-71f9ae618695" alt=""><figcaption></figcaption></figure>

## Clone States

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2Fd6msSb2UvHTnuOyHePxH%2Fimage.png?alt=media&#x26;token=279e0d02-21a0-4aa2-8d17-cdfc8223e947" alt=""><figcaption></figcaption></figure>

This option will clone all the State Scriptable assets at runtime. That way all the animals will have unique States.

{% hint style="success" %}
If you are using an animal as your Main Player, you can deactivate the **Clone State** option and modify internal values&#x20;
{% endhint %}

All States share common parameters to make easier to change properties to the Animal Controller while the core animation of the State is playing, or a new State or Mode is activated.

## Animator

All States require at least one Animation State in the Animator, even though you don't need or have one. you can always create an empty Animation State or use another existing animation clip.

## General

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FU67aTII8gWRga4dObgkL%2Fimage.png?alt=media&#x26;token=50cd53e3-2593-4a1d-b719-0e103eee02d7" alt=""><figcaption></figcaption></figure>

### **ID**

Unique [**ID**](https://malbersanimations.gitbook.io/animal-controller/scriptable-architecture/scriptables/scriptable-ids#states-ids) for the State that helps identify every state. These are added automatically when a State is created

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M-jWXW-c86xrpz7o6J8%2F-M-jbv1L7WcvgcvO_j7B%2FXZ5bSKQvjO.gif?alt=media\&token=f61c97fa-4e89-4933-861e-e4f3304da21a)

{% hint style="warning" %}

### IMPORTANT

The Name of the State (E.g. \[**Death]**) Is used and ***MUST BE SET*** as the **Main Tag** for the main animations of that State, otherwise, the controller wont work properly.
{% endhint %}

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M-jcZDDAKrB0qcfO-g5%2F-M-jd-B9drVbKbYU2b7-%2Fimage.png?alt=media\&token=71595aa3-2059-4a7b-bba4-994516aece0b)

### Priority

Priority of the State, Higher value -> Higher chance to be activated

This value is set automatically by the Animal Controller in each state. you can modify it on the State list too:

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FG3MJh5nvGpNp0BPBxUN3%2Fimage.png?alt=media&#x26;token=b342e16b-46c8-4ead-9e50-8c970631884e" alt="" width="467"><figcaption></figcaption></figure>

### State Profile

Allows different ways of using a State. Setting different values for the same type of State. E.g. If you had 2 flying profiles set up, one could be flying as Iron Man, and the other could be flying using a broom.

### Enter Input

Input to Activate the State. This parameter is completely optional, since some States activate automatically, like Swim (when the animal is near the water) or Fall (when there's no ground beneath the animal)

{% hint style="info" %}
Match the **Input** with the **Input** Item Name on any of the Malbers Input Component
{% endhint %}

![The name of the Input \[Jump\] matches with Malbers Input Jump slot ](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-McjL12xXQypP22mMo4i%2F-McjLbUYFJMZ_tCm_hzG%2Fimage.png?alt=media\&token=952a4bf0-d313-45ee-9894-a77347c0582f)

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M-jdO07Vr-zREYvmBHc%2F-M-jebUt2q2OsGDxA4fe%2Fimage.png?alt=media\&token=58a7f518-d097-462c-85fa-87269fe2a0d6)

{% hint style="info" %}
There are states that do **not** require Inputs to be activated, they are activated internally using the TryActivate() method.

Here are a few examples:

* Idle -> Movement Vector is Vector3.Zero.
* Locomotion -> Movement Vector is NOT Vector3.Zero.
* Fall -> There's no ground beneath the Animal.
* Swim -> The Animal is inside a Trigger with Layer: Water.
  {% endhint %}

You can also Activate any State using **`MAnimal.State_Activate(StateID state)`**. Just like the health State activates the Death State when Health is Empty. (Check it on Stats component -> Health Stat)

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-McjL12xXQypP22mMo4i%2F-McjNk4ICrRMWd4mTBZr%2Fimage.png?alt=media\&token=16a23fa8-1fb3-42de-9d68-13c92391b055)

### Exit Input

States can be allowed to exit if there's an Input connected  to this parameter

![The Climb State can exit if the Crouch Key is pressed (See Steve)](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2Fc5wWbSWCjOpvVMNh2jEN%2Fimage.png?alt=media\&token=122b1977-1a11-4165-9fff-0765b5eb2a1f)

### Reset Input on Failed

If the state is trying to be activated by an input and it fails for whatever reason (hint - check debug logs for more info!) then you can Reset the input value by toggling this

### Always Forward

Mark this as true if you want the character to only be able to go forward in this state e.g. endless runner type of games

### Reset Last State

When entering this state, the last state Animator parameter will be reset to -1

### Allow Exit From Anims

To Allow to Exit the state, the Animations need to use the **\[Allow Exit Behaviour]** on the Animator.

This is used when states require exit animations and they should not exit from the Main Animation State.

![Climb State require Exit Animations](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FUG2ZhQX6v2yL4wsXX0PK%2FUnity_UVCoAVuIsF.gif?alt=media\&token=070b5bf7-daea-4042-8d9e-48930702df12)

### Can Transition to Itself

The state can be activated even when it's already the current state e.g. if you are trying to do double/triple jumps

### Exit on Main

Set to true to Try and Exit the state on the Main State Animation. E.g. The Falling Animation can try to exit only when on the Fall Animation

### Enter Cooldown

Time needed to activate this state again after exit

### Exit Cooldown

Time needed to exit this state after being activated

### Try Loop

Try States will try and activate every x amount of frames

### Duration

Keeps the state enabled for x seconds, after which It will execute the internal AllowExit() state method - if it's set to 0, this will be ignored

### Can Strafe

Allows the character to strafe in this state

### Strafe Animations

This state has new Strafe Animations - if set to false, it will not update the animator with the \[StateOn] parameter

### Movement Strafe

Strafe multiplier when movement is detected - this will make the character be aligned to the strafe quicker at higher values

### Idle Strafe

Strafe Multiplier when there is no movement - this will make the character be aligned to the strafe quicker at higher values

## Tags

The Tags Modifier Property changes main features on the Animal Controller once the State enters the  MAIN Animations on the Animator Controller. The core tag value is the name of the ID - \[Speeds]

E.g. when the Animal Enter the MAIN **Fall** Animation on the **Fall** State we need:

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FZbFhGQ8Ea8PKmERUiryP%2Fimage.png?alt=media&#x26;token=6ff58e4c-afc0-43a3-a0f4-88700391fe1a" alt=""><figcaption></figcaption></figure>

* The Root Motion and Sprint to be Disabled&#x20;
* Enable the Gravity.
* Animal to **NOT** be Grounded or using a Custom Rotation
* Disable Ignore Lower States (Which Allows Lower Priority States to be Activated in case they can)
* Additional Positional Speed to be enabled.

{% hint style="info" %}

## Find out here what every[ Animal Modifier ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/animal-modifiers) does.

{% endhint %}

### Enter Tag

Animator Tag to identify Entering Animations on a State e.g. 'TakeOff' in Fly, 'EnterWater' in Swim

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FbS2yUqqq08VIuaHX0Sph%2Fimage.png?alt=media&#x26;token=25996d53-3320-4462-b2bd-1ec220191c83" alt=""><figcaption></figcaption></figure>

### Exit Tag

Animator Tag to identify Exiting Animations on a State e.g. 'Land' in Fall or 'SwimClimb' in Swim

### Exit Frame

When this is set to true, and the animal changes from a State to another, The Last State will execute another frame of logic while entering the new State

## Messages

When in the state, you can set up messages to send.

### Use SendMsg

When sending messages, when toggled true, it will use Unity's built in SendMessage, instead of the IAnimatorListener interface

### Children

When sending messages, it will send the messages to all the animal children gameobjects

## Animation Tags (additional modifiers)

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FEPPfUmPZtwvhoNAbtceO%2Fimage.png?alt=media&#x26;token=236124e2-464d-4765-ab17-99e1db242604" alt=""><figcaption></figcaption></figure>

You can use this section to set up additional modifiers based on when you activate certain animations in the state e.g. FallEdge, or Landing when in the fall state if you want those animations to have slightly different modifiers.

## Limits

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FGTktzWSjsSYveNHrPEMB%2Fimage.png?alt=media&#x26;token=12b0a7ea-0ba6-4406-a2bc-fa679fe06e17" alt=""><figcaption></figcaption></figure>

Limits allow you to set limitations to the states when another state, mode or stance is playing.

### Sleep From State

If the Active State is one of one on the list, the state can't be activated.

{% hint style="info" %}
Eg: the State [**Jump** ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/jump)is set to Sleep when the animal is on the [**Fall**](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/fall),  [**Fly**](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/fly), and [**UnderWater**](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/underwater) State
{% endhint %}

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M-lrvbrcXCfcYJnl6Qk%2F-M-lvtmCbqLR7Iwg5MfC%2Fimage.png?alt=media\&token=04b20c20-2c11-4f30-8340-c44ab300a3bc)

![Check the State List: The Jump State that is set to \[Sleep\] while is on Fall or Fly](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M-lrvbrcXCfcYJnl6Qk%2F-M-lv49Ya5dl7YE4JLmn%2FmnBc4cf01r.gif?alt=media\&token=ae8db9c9-0752-4f87-861f-89b235e0c5e1)

### Queue From

If the Active State is on the queue List. The state will be set on queue until the animal exit the Active State.

E.G. the Death State will be set on queue if the Animal is on the Fall State. and It will be activated once the Fall State finish.

### Reset From

If the state exits, it cannot be used again until one of these states on this list get's activated. E.g. You can disable Fly, and not use it again until the character uses idle or locomotion etc.

### Sleep From Mode

If a mode is Playing (E.g.: Attack, Action ) you can send a state to Sleep using the Sleep from Mode list. E.g.: The animal cannot Jump while is attacking.

![Check the State List: The Jump State that is set to \[SleepM\] while an Attack is Playing](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MWQsR__sKiTzm6vIy2D%2F-MWQuLONjbNL2FscACDf%2FaQPpuRcVXd.gif?alt=media\&token=0de6c875-2dfc-40f6-9fe6-ea45caee3d79)

### Sleep From Stance

If a stance is playing, you can send a state to sleep whilst the stance is playing. E.g. Whilst in the balance state for walking across a tightrope, you cannot jump etc.

### Allowed Stances

You can set stances that are allowed to be played whilst in this state. Leave empty to include all

### Debug

When the Editor is on Play mode the `State.Debug()` function is called.. and every State enables its gizmos and Log.

## **All included States so far:**

#### [Idle ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/idle)| [Locomotion ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/locomotion)| [Fall ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/fall)| [Basic Jump ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/jump-basic)| [Rootmotion Jump ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/jump)| [Swim ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/swim)| [UnderWater ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/underwater)| [Climb ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/climb)| [Fly ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/fly)| [Death](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states/death)

{% hint style="info" %}
More States will be added on the future with the addition of new Animals :grin:&#x20;
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
