AnimGraph Introduction
Overview
Source 2 AnimGraph is a data-driven system for dynamically compositing keyframed and procedural skeletal animation, and for controlling when to transition between compositions. It consists of two main parts: an editor for creating node-based graphs that define the animation behavior, and a runtime that evaluates the graphs during gameplay based in input from AI, navigation, environment, and other game systems.
The biggest difference to keep in mind when updating a Source 2 project to use AnimGraph is that game code is no longer directly telling the animation system which sequence to play. Instead, the game code provides the graph with commands and context about the game environment, and its up to the logic within the graph to determine what animations to play and how to play them. This allows the game code to focus on higher-level gameplay without having to micro-manage animation, and allows animators to create and iterate on better character performances without needing to understand C++.
AnimGraph Runtime
Model Binding
AnimGraphs are not tied to a specific model; the same graph can be used with multiple models provided that they all provide the same animations and other metadata that the graph requires. When a model is loaded and it references an animgraph, it will create a Binding for itself for that graph.
Data
AnimGraph data falls into 3 categories.
- Editor data: the data stored on disk and used in the editor. This data uses Schema for easy KV3 serialization and introspection. Its easily edited and extended
- Static Runtime Data: When the model binding is created the Editor data is packed into data that is more efficient for runtime evaluation. This runtime data is packed into a single contiguous block for cache efficiency. Once created it does not change at runtime, and is shared between all instances of entities that use the model to save memory
- Instance Runtime Data: All data that can change at runtime is packed into a separate buffer when the model binding is created. When a new instance of an entity is created, this instance data block is cloned so that each instance has its own copy. The static data, which contains the runtime logic for the graph nodes, references the instance data using handles.
Update Phases
The AnimGraph update is split into two phases.
The first phase is the Logic Update phase. In this stage the runtime walks the graph starting at the Root (aka "Final Pose") node, updating each node as it goes. Each node uses its internal logic to determine which, if any, of its children should be updated next. Its during this phase that blend amounts, animation cycles are advanced based on time, and events are collected and dispatched to listeners in the game code. Note that bone transforms are not involved during this phase.
The output of the logic update is a pose recipe. This is a compact representation of a series of skeletal pose operations to perform in order to create the final bone transforms that should be used to render the character at that time.
The Pose Evaluation phase runs after the logic update phase. It runs the pose operations defined in the pose recipe to create the final skeletal pose. The Pose Evaluation phase is always run on the client, because the latest bones transforms are always needed for rendering. However to save performance, it is not necessary to always run Pose Evaluation on the server, as often the actual bone transforms are not needed.
The AnimGraph keeps a cache of the most recent pose recipes so that older poses can be evaluated when necessary. For example, when performing hit testing in a networked environment it is often useful to evaluate the pose from the time that the shot was taken to determine whether or not the shot was was successful.
AnimGraph Editor
The editor is where you create the graphs that are used by the runtime, test them out in a controlled environment, and debug any errors that you discover.
Editor Panels:
Main Panel
This is the main area of the editor. It shows a detailed editor for item that is currently being viewed.
By default, it shows all of the nodes and connections at the top level of the graph, but is reused to show specific editor visualizations for more complicated nodes such as state machines and motion matching. Nodes with an indicator in their top-right corner like this can be double-clicked to open their specific editor.
Preview Window
The preview window shows the animation created by running the graph applied to one or more models in real-time when in Preview Mode.
Controls:
- Left Mouse: Use active tool (in preview mode)
- Left mouse + Alt: rotate around center of scene
- Right mouse: turn camera. Hold down and use WSAD key to fly the camera around in first person mode
- Right mouse + Alt: zoom
- Middle mouse: pan
- Mouse wheel: zoom
Main Inputs
This panel displays and lets the user control values that are common to all AnimGraphs. This includes things like the look direction and the current slope
Motors
Allows you to add, edit, and remove Motors
Parameters
Allows you to add, edit, and remove AnimGraph Parameters
Tags
Allows you to add, edit, and remove AnimTags
Playback Control
Controls the playback of the AnimGraph in Preview Mode. Press the Start Preview button to enter Preview Mode and run the current graph in the editor. You can also load AnimGraph Replay recordings from this panel
Console
Displays any errors or warnings about potential problems with the graph when you enter preview mode.
Properties Panel
This panel will display the properties of the currently selected item. This consists of a list of basic properties, and may also include some more detailed information as sub-panels such as mini-editors or 3D previews.
Search Bar
AnimGraphs can get big, and when they do it can be hard to find the node you're looking for. Click on the search box or press Ctrl+f to search the name of a node, node type, or property in the graph. You can also search for Tags or Parameters and the search results will show you all the places where they are used.