Character Controller Pro (1.4.x)
  • Introduction
  • The package
    • Content
    • Versioning scheme
    • Importing the package
    • Using the package
    • Known issues
  • Fundamentals
    • Core
      • Character
      • Character body
      • Character actor
        • States
        • Stable movement features
        • Velocity
    • Implementation
      • Character state controller
      • Character state
      • Character brain
  • How to...
    • Core
      • Create a basic character
      • Add behavior logic to your character
      • Move the character
      • Rotate the character
      • Leave grounded state (e.g. jump)
      • Change the size of the character
      • Disable collisions (ghost)
      • Use the character information (with examples)
      • Use root motion
      • Detect a character using a "detector"
      • Add a static one way platform
      • Add a dynamic one way platform
    • Implementation
      • Organize the character hierarchy
      • States
        • Add and configure the state machine
        • Create a state
        • Transition from one state to another
        • Handle animation
        • Modify an IK (inverse kinematics) element
      • Actions
        • Define your own actions
        • Use the character actions
        • Use a custom Input Handler
        • Use the new input system
        • Create your own AI movement logic
Powered by GitBook
On this page
  • Getting a reference to the actor
  • Update message
  • Execution order
  1. How to...
  2. Core

Add behavior logic to your character

Getting a reference to the actor

using UnityEngine;
using Lightbug.CharacterControllerPro.Core; //<-- Required

public class CharacterLogic: Monobehaviour
{
    [SerializeField]
    CharacterActor characterActor = null;
}

Update message

Because the actor is a rigid body that's going to be affected by the physics simulation, all the logic must be located on FixedUpdate.

using UnityEngine;
using Lightbug.CharacterControllerPro.Core; //<-- Required

public class CharacterLogic: Monobehaviour
{
    [SerializeField]
    CharacterActor characterActor = null;
    
    void FixedUpdate()
    {        
        // Put the logic here ...
    }
}

Execution order

By default, the CharacterActor class uses an execution order of 10. This means all scripts without the attribute (execution order = 0) will run before CharacterActor, which is what we want.

//CharacterActorOrder = 10
[DefaultExecutionOrder(ExecutionOrder.CharacterActorOrder)]
public class CharacterActor : MonoBehaviour
{
    ...
}
PreviousCreate a basic characterNextMove the character

Last updated 6 months ago

Because the actor runs its own update, it is important for the behavior logic (user-defined) to run before it. In Unity the execution order of scripts can be specified either in the project settings, or as a c# attribute called .

DefaultExecutionOrder