🆕Creating a new State
Steps to create a new state by code. ... Finishing up
Overview
To create a new state from scratch you need to create a script that inherits from the State class
This class needs to be on the
MalbersAnimations.ControllernamespaceImplement the StateName Property. This Holds the Menu Display name when you add a new State on the Animal Controller.

Once you create the new script you will need to create a new State ID to Identify your new State. On your project window. Use the Create menu to add a new state:

Or you can simply duplicate any StateID already created, rename it, and change the ID value:

Example State
Methods and Properties
To Create a new custom state you will need to implement some of the methods used to Activate, try to activate, move the Animal while is in the state, and Exit the state.

bool TryActivate()
This method is like the Automatic Method Activation for the states... If this method returns true... the New State will be activated. For example, in the Fall State, I use this method to cast the Pink Ray, to find the ground beneath the animal... if I don't find the ground or I find a slope too deep I return true and the state will be activated.
Not all states need to implement this method. States like Fly and Death can be activated by Player Input or by calling directly the Activate() method.
void Activate()
This method is called right after the TryActivate(), or if an Input activated the State. or by simply calling State_Activate(int ID) on the Animal.
Here all the Animator Parameters are updated. That way, in the next frame, the animations are properly executed.
In this method, is mandatory to keep the base.Activate(); reference.
This is an example of the Fall State:

void EnterCoreAnimation()
This method is called when the first frame of the Core animation of the state is played. E.g. when the glide state Animation with the "Glide" tag plays

This method does not require you the use of <base.> logic on methods.
void EnterTagAnimation()
This method is called everytime the state enters any Animation Tagged.
E.g. Lomotion has custom tags like Land, StartLocomotion, Locomotion. This method is called every time a new Custom Tag is playing
void OnStateMove(float DeltaTime)
This is the Update of the State... all the logic of the state is here. All the state custom movement you want to do, it is done here.
E.g. the Fall State adds Air Control to move the character and applies gravity.
void TryExitState(float DeltaTime)
The logic for exiting the state is here. Add all the conditions you need to allow your state to exit.
if the State allows conditions are true. Call the AllowExit() method.
E.g. on the Glide and Fall State; if the character is near the ground, I call AllowExit() here... which will allow other states to try to activate themselves.

void ResetStateValues()
In this method you need to restore all the internal variables of your state.... so the next time is activated again ...all the local variables are clean/reset.
void RestoreAnimalOnExit()
Here... you need to restore the animal variables you changed only for this state... (E.g. With Glide, I enable the Animal AlwaysForward parameter and I disable it when Glide is finished)
...KEEP.. Going 😅😫
Last updated
Was this helpful?