🔷States
Last updated
Last updated
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.
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()
will permit again the lower states a chance to activate themselves.
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.
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 use set the Fly ID there
This option will clone all the State Scriptable assets at runtime. That way all the animals will have unique States.
If you are using an animal as your Main Player, you can deactivate the Clone State option and modify internal values
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.
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.
Unique ID for the State that helps identify every state. These are added automatically when a State is created
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:
Allows different ways of using a 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.
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)
Match the Input with the Input Item Name on any of the Malbers Input Component
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.
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)
States can be allowed to exit if there's an Input connected to this parameter
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
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
When entering this state, the last state Animator parameter will be reset to -1
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.
The state can be activated even when it's already the current state e.g. if you are trying to do double/triple jumps
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
Time needed to activate this state again after exit
Time needed to exit this state after being activated
Try States will try and activate every x amount of frames
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
Allows the character to strafe in this state
This state has new Strafe Animations - if set to false, it will not update the animator with the [StateOn] parameter
Strafe multiplier when movement is detected - this will make the character be aligned to the strafe quicker at higher values
Strafe Multiplier when there is no movement - this will make the character be aligned to the strafe quicker at higher values
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:
The Root Motion and Sprint to be Disabled
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.
Animator Tag to identify Entering Animations on a State e.g. 'TakeOff' in Fly, 'EnterWater' in Swim
Animator Tag to identify Exiting Animations on a State e.g. 'Land' in Fall or 'SwimClimb' in Swim
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
When in the state, you can set up messages to send.
When sending messages, when toggled true, it will use Unity's built in SendMessage, instead of the IAnimatorListener interface
When sending messages, it will send the messages to all the animal children gameobjects
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 allow you to set limitations to the states when another state, mode or stance is playing.
If the Active State is one of one on the list, the state can't be activated.
Eg: the State Jump is set to Sleep when the animal is on the Fall, Fly, and UnderWater State
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.
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.
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.
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.
You can set stances that are allowed to be played whilst in this state. Leave empty to include all
When the Editor is on Play mode the State.Debug()
function is called.. and every State enables its gizmos and Log.
More States will be added on the future with the addition of new Animals 😁