Animal Controller
📥 Integrations📑 Changelog✅Social
  • 🤝Welcome to Malbers Animations Assets
  • 🌐Discover all my Assets
  • 💫What's New
  • 🌀Upcoming assets
  • 📋Changelog
  • ↗️Upcoming Changelog
  • 🛣️Road Map
  • ✍️End User Licence Agreement
  • 🌟Features
  • Improve Performance Tricks
  • 😓Know Limitations so far
  • 📥Downloads
  • QuickStart
    • 📖Guide to use All Malbers Assets with (AC)
    • 🔼Upgrade to URP
    • 🔼Upgrade to HDRP
    • 💔Common Issues
    • 🔔Tips and Tricks
  • Guides and Tutorials
  • 📺YouTube Tutorials
    • 📺Video Tutorials (On Queue)
  • 📱Mobile Setup Guide
    • Mobile Joystick
  • 🧐How to: Animal Controller
    • 🔹Play a Mode while Moving
    • 🔹Create and configure a new mode
    • 🔊Adding Sound Effects
    • 🔹Rebone Mesh Tutorial (Skin Mesh is Missing)
    • 🔹Add Movement with Non RootMotion Animations
    • 🔹Fetch a ball
    • 🔹Set up Timeline
    • 🔹Make Animal flee when see the animal Player
    • 🔹Animal Controller for Humanoids
    • Create a Shootable Weapon From Scratch
    • ⚔️How to Fix weapons offset and values (Bow, Pistol)
    • ✨Add a Effect to the Effect Manager
    • 🕹️Connect Inputs to the Controller
    • Modify the controller with a Stat
    • Use the Modify Stat Component
    • 📡Use a MEvent and MEvent Listeners
    • 💎Change from Faceted to Smooth poly art Animals
    • ⁉️Listen when an Mode starts or ends
  • 🐎How to: Horse Animset Pro
    • 🐴Call the Mount
    • 🤠Change Meshes for the Rider
    • 🏇Make any animal mountable
  • 🕺Strafing
  • Main Components
    • 🐺MAnimal Controller
      • General
        • Pivots
      • Speeds
      • 🔷States
        • 🕴️Idle
        • 🏃‍♂️Locomotion
        • 🌠Fall
        • 🤾‍♀️Basic Jump
        • 🤾‍♂️Root Motion Jump
        • 🐟Swim
        • 🐊UnderWater
        • 🧗‍♂️Climb
        • 🧗‍♂️Ledge Grab
        • 🦅Fly
        • 🪂Glide
        • 🧗Wall Run
        • 🧗Wall Run Vertical
        • ⛷️Slide
        • ☠️Death
        • ☠️Death Ragdoll
        • 🆕Creating a new State
      • 🟩Modes
        • 🟩Mode Behavior
        • 🟩Mode Sequence
      • 🅾️Stances
      • Advanced
      • Animal Modifiers
      • Events
      • Debug
      • Animal Animator Behaviors
      • Methods and Properties
    • 🎮Malbers Input & MInput
      • Methods and Properties
    • 🤖AI
      • AI Animal Control
      • MWayPoint
      • Wander Area
      • AI Target
      • Animal Brain
        • AI States
        • Tasks
          • General - Chance
          • General - Empty
          • General - Invoke Event
          • General - Send Message
          • General - Play Audio
          • General - Quick Align
          • General - Reaction
          • General - Set Look At Aim
          • General - Set Stat
          • General - Wait
          • Animal - Set Speed
          • Animal - Play Mode
          • Animal - Set/Play State
          • Animal - Set Stance
          • Animal - Set Strafe
          • Movement - Move Stop
          • Movement - Patrol
          • Movement - Set Destination
          • Movement - Set Target
          • Variables - Set Var Listener
          • Weapons - Weapon Tasks
        • Decisions
          • General - AND
          • General - Check Stat
          • General - Compare Stats
          • General - Look
          • General - OR
          • General - Is Task Done?
          • General - Wait
          • Movement - Has Arrived
          • Movement - Check Target
          • Animal - Check Mode
          • Animal - Check Stance
          • Animal - Check State
          • Variables - Check Scriptable Variable
          • Variables - Check Transform Var
          • Variables - Check Var Listener
          • Runtime Set - Is Target in Runtime Set
      • 📌Point Click
    • 🧨Reactions
    • 📶Combo Manager
    • ⚔️Weapon Manager
      • 🛡️MWeapon [General] Properties
      • 🛡️MWeapon [Damage] Properties
      • 🛡️MWeapon [IK] Properties
      • ⚔️MMelee
      • 🔫MShooteable
      • 🏹Bow
    • 〰️Path Constraint
      • 〰️MPath
      • 〰️Path Link (Straight)
      • 〰️Path Link (Cinemachine Path)
      • 〰️Path Creator(Sebastian Lague)
    • Speed Ground Changer
  • Scriptable Architecture
    • 💠Scriptables
      • 🔹Bool Var
      • 🔹Int Var
      • 🔹Float Var
      • 🔹String Var
      • 🔹ValueToString
      • 🔢Variable Listeners & Comparers
      • 🔰IDs
      • 🎫Tags
      • 🪝Transform Hook
      • 📣MEvents
      • 📣MEvent Listener
      • 📦Runtime gameobjects
    • 🔤MLocal Variables
  • Secondary Components
    • ⚔️MDamager
      • 🐾MAttack Trigger
      • 🐾Attack Trigger Behavior
      • 🏉MProjectile
      • 🏹Projectile Thrower
      • 🤯MExplosion
    • 🤕MDamageable
    • 🧊Zones
      • Public Methods
    • ✊Pick Up - Drop
    • ✊Pickable
    • 🚩Respawner
    • 🚩Respawner NPC
    • 🚩Simple Respawner
    • 🏁CheckPoint
    • IK Manager
      • IK Processors
      • Weight Processors
  • Global Components
    • 🧡Stats
      • 🔸Stat Modifier
      • 🔸Modify Stat <Component>
      • 🔸Modify Stat <Asset>
      • 👨‍💻Public Methods
    • Animator Behaviours
      • Message Behaviour
      • Random Behaviour
      • Is Kinematic Behaviour
      • Sound Behaviour
      • Rigid Constraint Behaviour
    • 🟩Trigger Proxy
    • 🔌Interactable
    • ⚡Interactor
    • ⁉️Conditions
    • 🎥Free Look Camera
    • 🎥Cinemachine
    • UI
      • Unity Utils
  • Riding System (HAP)
    • Horse Animset Pro (HAP) Riding System
    • The Art of (HAP)
    • Mount
      • Methods and Properties
    • MRider
      • Methods and Properties
    • Mount Triggers
    • Mount Points
  • Utilities
    • Material Changer
    • Active Meshes
    • Effect Manager
    • Effect Behavior
    • Animator Event Sounds
    • Blend Shapes
      • Blend Shape Preset
    • Look At
    • 🏹Aim
    • 🎯Aim Target
    • 🎯Lock On Target
    • 🐾Steps Manager
    • 🐾Step Trigger
    • 🔗Mode Align
    • 🔗Aligner
    • Component Selector
    • MAnimalAnimatorSync
    • Multiple Time Checker
    • MAnimalAnimatorSync
  • Annex
    • 🗃️Integrations
      • General HAP Integration
      • Rewired
      • Invector Templates
        • Invector Weapon Settings
      • Animals Controller + Invector
      • Ootii's Motion Controller
      • Opsive Ultimate Character Controller (UCC 3.03)
      • Opsive Ultimate Character Controller (UCC 3.08) Generic
      • AStar Pathfinding
      • Unity Input System (NEW)
        • New Input Link [Old Versions]
      • Game Creator
      • Game Kit Controller
    • Contact
    • 🤔FAQ
    • Refund Policy
  • Games using Malbers Animations
  • Interfaces
    • IAITarget
    • IWayPoint
    • IAIControl
    • IAim
    • IAlign
    • IGravity
    • IInteractor
  • ULTIMATE SELECTOR
    • Overview
    • Selector Manager
    • Selector Editor
    • Selector Controller
    • Selector Item
    • Selector UI
    • Selector Data
    • Changelog (Selector)
  • 🎒Malbers Inventory Add-On
    • Overview
      • Compatibility Matrix
      • Roadmap
      • Update Notes
  • Updating from v1.1.1 to v1.2 Instructions
  • Basic Setup Instructions
    • Creating a new Item
      • Adding Buffs/Debuffs to Items
      • Setting up Item Reactions
      • Custom Rarities
    • Setting up Item/Inventory Types
    • Set up the Pick/Drop Component
    • Setting up the Notifications
    • Setting up the Item Info panel
  • Inventory Set
    • Events
  • Inventory Master
  • Notification Manager
    • Notification Child
    • Events
  • Save/Load System
  • Item Spawner
  • Storage Chests
    • Chest Inventory
    • Chest Inventory UI
  • Using Armour
  • Shop System
    • Shop
    • Shop UI Manager
  • Cooking System
    • Create a new Recipe
  • UI Manager
  • Hotbar
Powered by GitBook
On this page
  • Overview
  • Example State
  • Methods and Properties
  • bool TryActivate()
  • void Activate()
  • void EnterCoreAnimation()
  • void EnterTagAnimation()
  • void OnStateMove(float DeltaTime)
  • void TryExitState(float DeltaTime)
  • void ResetStateValues()
  • void RestoreAnimalOnExit()

Was this helpful?

  1. Main Components
  2. MAnimal Controller
  3. States

Creating a new State

Steps to create a new state by code. ... Finishing up

PreviousDeath RagdollNextModes

Last updated 1 year ago

Was this helpful?

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.Controller namespace

  • Implement 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

using UnityEngine;

namespace MalbersAnimations.Controller
{
     
    [CreateAssetMenu(menuName = "Malbers Animations/TemplateState", fileName = "TemplateState", order = 4000)]
    public class TemplateState : State
    {
        // Define state name and ID
        public override string StateName => "TemplateState";
        public override string StateIDName => "TemplateState";

        // Internal variables
        private bool yourChecker; // Check if a condition is met
        private int exitStatusNumber; // Track exit status


        // Method called when state transition is triggered by input
        public override void StatebyInput()
        {
            yourChecker = false; // Reset checker
            if (InputValue) // Check for input condition
            {
                Activate(); // Activate the state
            }
        }

        // This method is like use for automatic states, or states that require external conditions for Activation
        // 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.
        public override bool TryActivate()
        {
            return yourChecker;
        }



        // Method 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, it is mandatory to keep the base.Activate(); reference.
        public override void Activate()
        {// Start function

            CheckFunction(); // Check condition
            if (yourChecker) // If condition is met
            {
                base.Activate(); // Mandatory call
               // Additional logic for updating animator parameters
            }
        }

        // Method called when entering core animation. The core animation must have the Core Tag in the Animator Controller
        public override 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.
            // Example: This method could be used to initialize specific actions when entering core animation.
        }

        // Method called when entering animation tagged with specific tags
        public override void EnterTagAnimation()
        {
            // This method is called every time the state enters any Animation Tagged.
            // E.g. Locomotion has custom tags like 'Land', 'StartLocomotion', 'Locomotion'.
            // This method is called every time a new Custom Tag is playing.
        }

        // Custom check function. Some States require external verifications and conditions to be activated.
        //E.g. The Climb State requires a Wall with an Specific Layer and a Collider
        //A raycast will be cast to verify is a wall in front of the characcter is valid to be climbed
        private void CheckFunction()
        {
            yourChecker = true; // Set checker to true
        }

        // State logic update method.
        // This method handles all the state-specific logic. It's where you implement custom movements and behaviors for the state.
        // E.g. the Fall State, it manages air control to move the character and applies gravitational forces.
        // Example: ApplyGravity(); ApplyAirControl();
        public override void OnStateMove(float deltaTime)
        {
            if (InCoreAnimation)
            {
                // Core update functions

                AllowExit();
            }
        }


        // Method called when state exit is triggered by input
        public override void StateExitByInput()
        {
            // Example: SetExitStatus(exitStatusNumber);
        }

        // Reset state-specific variables
        public override void ResetStateValues()
        {
            // Here, 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.
            // Example: Reset all your state-specific variables
        }

        // Restore animal variables upon state exit
        public override void RestoreAnimalOnExit()
        {
            // Here, you need to restore the animal variables you changed only for this state.
            // Example: Reset all animal variables
        }
    }
}

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 😅😫

🐺
🔷
🆕
Always add <base.> logic on methods that have code in the parent State class.
Glide TryExit method