101 lines
4.5 KiB
Plaintext
101 lines
4.5 KiB
Plaintext
Availability:NoPublish
|
|
Title: State Machines
|
|
Crumbs:
|
|
Description:State Machines allow Skeletal Animations to be broken up into various states, with full control over how blends occur from one state to another.
|
|
|
|
[EXCERPT:DummyExcerpt]
|
|
|
|
[/EXCERPT:DummyExcerpt]
|
|
|
|
|
|
|
|
[EXCERPT:UAnimStateNode]
|
|
|
|
Conceptually, it is best to think of a state as just an organized portion of an AnimGraph that we know the character or Skeletal Mesh will be blending into and out of on a regular basis. You can then transition into and out of this part of the graph. For instance, you may have an Idle state for your character's animation, and that state may just contain a single animation.
|
|
|
|
Here is such an Idle state seen from the State Machine.
|
|
|
|

|
|
|
|
When double-clicked, here is the simple graph found within that Idle state.
|
|
|
|

|
|
|
|
Once the character started, moving, however, they could transition into a Movement state - which could define moving laterally across a surface, like walking or running.
|
|
|
|

|
|
|
|
Within, this state may contain a [BlendSpace](Engine/Animation/Blendspaces) that is being defined by the character's speed and direction of movement.
|
|
|
|

|
|
|
|
States have no pins in and of themselves, because they are intended to have a more freeform layout. To connect a state to any other state, simply drag a wire from its outer border. This can also be used to create new states, just like making new nodes in a Blueprint.
|
|
|
|

|
|
[/EXCERPT:UAnimStateNode]
|
|
|
|
|
|
|
|
|
|
[EXCERPT:UAnimStateConduitNode]
|
|
|
|
|
|
Conduits serve as a more advanced and sharable transition resource. Where a Transition Rule is going to be a simple 1-to-1 relationship form one state to another, a Conduit can have 1-to-many, many-to-1, or many-to-many.
|
|
|
|

|
|
|
|
For instance, you may have a situation where you have multiple animations that could play when a character is killed. You could start with a simple Transition Rule that says when the health of that character is less than or equal to 0, then go to a Death state. However, if instead of a State, the transition went into a Conduit, you could perform a series of checks to see how the player was killed (shot, stabbed, explosion, hit by a car, anvil on the head, etc.) and branch from there into various independent death States.
|
|
|
|
Such a graph - although a bit simplified - may look something like this:
|
|
|
|

|
|
|
|
Inside, a Conduit graph looks just like a Transition Rule:
|
|
|
|

|
|
|
|
The actual transition rules that exit the Conduit can then determine the type of death and allow blending to the appropriate state.
|
|
[/EXCERPT:UAnimStateConduitNode]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[EXCERPT:UAnimStateTransitionNode]
|
|
|
|
|
|
Once you have your states defined, you need to be able to control how your Skeletal Mesh is going to transition from one state to another. This is where Transition Rules come into play. Transition rules are created automatically along the wires that connect states.
|
|
|
|

|
|
|
|
Transition rules can perform any number of checks and tests against variable values, all with the purpose of outputting a True/False value. This Boolean output determines whether the animation can move through the transition or not.
|
|
|
|

|
|
|
|
In this example, we are testing the value of a character's Speed. Once it reaches a value greater than 10, we enable the transition. In this case, the character is allowed to move from an Idle state to a Movement state. We can then use a completely separate rule to transition back to Idle. For example, here we have a transition rule moving back from Movement to Idle.
|
|
|
|

|
|
|
|
Inside, this simply checks to see if the same value we used to transition _into_ the Movement state is no longer true.
|
|
|
|

|
|
|
|
For more information on Transition Rules and their properties, please see the [Transition Rules documentation.](Engine/Animation/StateMachines\TransitionRules)
|
|
[/EXCERPT:UAnimStateTransitionNode]
|
|
|
|
|
|
|
|
|
|
|
|
[EXCERPT:UAnimGraphNode_Root]
|
|
|
|
After processing your animation in the AnimGraph, wire the final animation pose result into this node to apply it to the mesh.
|
|
[/EXCERPT:UAnimGraphNode_Root]
|
|
|
|
|
|
[EXCERPT:UAnimGraphNode_StateMachine]
|
|
|
|
A state machine is a collection of states, transitions, and conduits. The machine will change state based upon the rules defined in the state transitions. Each state is conceptually a self contained AnimGraph and can output an animation pose. This can then be further manipulated in the AnimGraph that contains the state machine.
|
|
[/EXCERPT:UAnimGraphNode_StateMachine]
|