Skip to content

AnimationNodeBlendSpace2D

Inherits: AnimationRootNode < AnimationNode < Resource < RefCounted < Object

A set of AnimationRootNodes placed on 2D coordinates, crossfading between the three adjacent ones. Used by AnimationTree.

A resource used by AnimationNodeBlendTree.

AnimationNodeBlendSpace2D represents a virtual 2D space on which AnimationRootNodes are placed. Outputs the linear blend of the three adjacent animations using a Vector2 weight. Adjacent in this context means the three AnimationRootNodes making up the triangle that contains the current value.

You can add vertices to the blend space with add_blend_point() and automatically triangulate it by setting auto_triangles to true. Otherwise, use add_triangle() and remove_triangle() to triangulate the blend space by hand.

Optionally, signals can be used by setting an AnimationNodeObserverBlendSpace through AnimationTree.

var observer = animationTree.Get("parameters/BlendSpace/observer").As<AnimationNodeObserverBlendSpace>();
observer.ClosestPointChanged += OnClosestPointChanged;
Type Name Default
bool auto_triangles true
BlendMode blend_mode 0
float cyclic_length 0.0
Vector2 max_space Vector2(1, 1)
Vector2 min_space Vector2(-1, -1)
Vector2 snap Vector2(0.1, 0.1)
SyncMode sync_mode 0
String x_label "x"
String y_label "y"
Returns Method
void add_blend_point(node: AnimationRootNode, pos: Vector2, at_index: int = -1, name: StringName = &"")
void add_triangle(x: int, y: int, z: int, at_index: int = -1)
int find_blend_point_by_name(name: StringName) const
int get_blend_point_count() const
StringName get_blend_point_name(point: int) const
AnimationRootNode get_blend_point_node(point: int) const
Vector2 get_blend_point_position(point: int) const
int get_triangle_count() const
int get_triangle_point(triangle: int, point: int)
void remove_blend_point(point: int)
void remove_triangle(triangle: int)
void reorder_blend_point(from_index: int, to_index: int)
void set_blend_point_name(point: int, name: StringName)
void set_blend_point_node(point: int, node: AnimationRootNode)
void set_blend_point_position(point: int, pos: Vector2)

triangles_updated

triangles_updated()

Emitted every time the blend space’s triangles are created, removed, or when one of their vertices changes position.

BlendMode

enum BlendMode

BLEND_MODE_INTERPOLATED = 0

The interpolation between animations is linear.

BLEND_MODE_DISCRETE = 1

The blend space plays the animation of the animation node which blending position is closest to. Useful for frame-by-frame 2D animations.

BLEND_MODE_DISCRETE_CARRY = 2

Similar to BLEND_MODE_DISCRETE, but starts the new animation at the last animation’s playback position.

SyncMode

enum SyncMode

SYNC_MODE_NONE = 0

Inactive animations are frozen and do not advance.

SYNC_MODE_INDEPENDENT = 1

Inactive animations advance with a weight of 0. This is equivalent to the previous sync = true behavior.

SYNC_MODE_CYCLIC_MUTABLE = 2

All animations are time-scaled so they stay in sync, with the cycle length dynamically computed from active blend weights. This is self-normalizing: a solo animation plays at normal speed.

Note: If you apply AnimationNodeTimeSeek to the result when handling animations of different lengths, synchronization will be broken. In such cases, it is recommended to use AnimationNodeAnimation.use_custom_timeline to align the animation lengths.

SYNC_MODE_CYCLIC_CONSTANT = 3

All animations are time-scaled so they complete one cycle in cyclic_length seconds, keeping them in sync regardless of their individual lengths.

Note: If you apply AnimationNodeTimeSeek to the result when handling animations of different lengths, synchronization will be broken. In such cases, it is recommended to use AnimationNodeAnimation.use_custom_timeline to align the animation lengths.

auto_triangles

bool auto_triangles = true

If true, the blend space is triangulated automatically. The mesh updates every time you add or remove points with add_blend_point() and remove_blend_point().

blend_mode

BlendMode blend_mode = 0

Controls the interpolation between animations.

cyclic_length

float cyclic_length = 0.0

The cycle length in seconds used by SYNC_MODE_CYCLIC_CONSTANT. All animations are time-scaled so they complete one full cycle in this duration. Must be greater than 0 for cyclic sync to take effect.

max_space

Vector2 max_space = Vector2(1, 1)

The blend space’s X and Y axes’ upper limit for the points’ position. See add_blend_point().

min_space

Vector2 min_space = Vector2(-1, -1)

The blend space’s X and Y axes’ lower limit for the points’ position. See add_blend_point().

snap

Vector2 snap = Vector2(0.1, 0.1)

Position increment to snap to when moving a point.

sync_mode

SyncMode sync_mode = 0

Controls how animations are synced when blended. See SyncMode for available options.

x_label

String x_label = "x"

Name of the blend space’s X axis.

y_label

String y_label = "y"

Name of the blend space’s Y axis.

add_blend_point

void add_blend_point(node: AnimationRootNode, pos: Vector2, at_index: int = -1, name: StringName = &"")

Adds a new point with name that represents a node at the position set by pos. You can insert it at a specific index using the at_index argument. If you use the default value for at_index, the point is inserted at the end of the blend points array.

Note: If no name is provided, safe index is used as reference. In the future, empty names will be deprecated, so explicitly passing a name is recommended.

add_triangle

void add_triangle(x: int, y: int, z: int, at_index: int = -1)

Creates a new triangle using three points x, y, and z. Triangles can overlap. You can insert the triangle at a specific index using the at_index argument. If you use the default value for at_index, the point is inserted at the end of the blend points array.

find_blend_point_by_name

int find_blend_point_by_name(name: StringName) const

Returns the index of the blend point with the given name. Returns -1 if no blend point with that name is found.

get_blend_point_count

int get_blend_point_count() const

Returns the number of points in the blend space.

get_blend_point_name

StringName get_blend_point_name(point: int) const

Returns the name of the blend point at index point.

get_blend_point_node

AnimationRootNode get_blend_point_node(point: int) const

Returns the AnimationRootNode referenced by the point at index point.

get_blend_point_position

Vector2 get_blend_point_position(point: int) const

Returns the position of the point at index point.

get_triangle_count

int get_triangle_count() const

Returns the number of triangles in the blend space.

get_triangle_point

int get_triangle_point(triangle: int, point: int)

Returns the position of the point at index point in the triangle of index triangle.

remove_blend_point

void remove_blend_point(point: int)

Removes the point at index point from the blend space.

remove_triangle

void remove_triangle(triangle: int)

Removes the triangle at index triangle from the blend space.

reorder_blend_point

void reorder_blend_point(from_index: int, to_index: int)

Swaps the blend points at indices from_index and to_index, exchanging their positions and properties.

set_blend_point_name

void set_blend_point_name(point: int, name: StringName)

Sets the name of the blend point at index point. If the name conflicts with an existing point, a unique name will be generated automatically.

set_blend_point_node

void set_blend_point_node(point: int, node: AnimationRootNode)

Changes the AnimationNode referenced by the point at index point.

set_blend_point_position

void set_blend_point_position(point: int, pos: Vector2)

Updates the position of the point at index point in the blend space.