unreal.Vector

class unreal.Vector(x=0.0, y=0.0, z=0.0)

Bases: unreal.StructBase

A point or direction FVector in 3d space. note: The full C++ class is located here: EngineSourceRuntimeCorePublicMathVector.h

C++ Source:

  • Module: CoreUObject

  • File: NoExportTypes.h

Editor Properties: (see get_editor_property/set_editor_property)

  • x (double): [Read-Write] X

  • y (double): [Read-Write] Y: Alias for float/double depending on LWC status. Note: Will be refactored to double before UE5 ships.

  • z (double): [Read-Write] Z

BACKWARD = None

3D vector Unreal backward direction constant (-1,0,0)

Type

(Vector)

DOWN = None

3D vector Unreal down direction constant (0,0,-1)

Type

(Vector)

FORWARD = None

3D vector Unreal forward direction constant (1,0,0)

Type

(Vector)

LEFT = None

3D vector Unreal left direction constant (0,-1,0)

Type

(Vector)

ONE = None

3D vector one constant (1,1,1)

Type

(Vector)

RIGHT = None

3D vector Unreal right direction constant (0,1,0)

Type

(Vector)

UP = None

3D vector Unreal up direction constant (0,0,1)

Type

(Vector)

ZERO = None

3D vector zero constant (0,0,0)

Type

(Vector)

__add__(other)

Overloads:

  • Vector Vector addition

__eq__(other)

Overloads:

  • Vector Returns true if vector A is equal to vector B (A == B)

__iadd__(other)

Overloads:

  • Vector Vector addition

__imul__(other)

Overloads:

  • Vector Element-wise Vector multiplication (Result = {A.x*B.x, A.y*B.y, A.z*B.z})

  • double Scales Vector A by B

__isub__(other)

Overloads:

  • Vector Vector subtraction

__mul__(other)

Overloads:

  • Vector Element-wise Vector multiplication (Result = {A.x*B.x, A.y*B.y, A.z*B.z})

  • double Scales Vector A by B

__ne__(other)

Overloads:

  • Vector Returns true if vector A is not equal to vector B (A != B)

__neg__()

Negate a vector.

__or__(other)

Overloads:

__sub__(other)

Overloads:

  • Vector Vector subtraction

__truediv__(other)

Overloads:

  • Vector Element-wise Vector division (Result = {A.x/B.x, A.y/B.y, A.z/B.z})

  • double Vector divide by a float

__xor__(other)

Overloads:

add(b) Vector

Vector addition

Parameters

b (Vector) –

Return type

Vector

add_bounded(add_vect, radius) None

Add a vector to this and clamp the result to an axis aligned cube centered at the origin.

Parameters
  • add_vect (Vector) – Vector to add.

  • radius (float) – Half size of the cube.

add_float(b) Vector

Adds a float to each component of a vector

Parameters

b (double) –

Return type

Vector

add_int(b) Vector

Adds an integer to each component of a vector

Parameters

b (int32) –

Return type

Vector

assign(vector) None

Assign the values of the supplied vector.

Parameters

vector (Vector) – Vector to copy values from.

bounded_to_box(box_min, box_max) Vector

Get a copy of this vector, clamped inside of the specified axis aligned cube.

Parameters
Return type

Vector

bounded_to_cube(radius) Vector

Get a copy of this vector, clamped inside of an axis aligned cube centered at the origin.

Parameters

radius (float) – Half size of the cube (or radius of sphere circumscribed in the cube).

Returns

A copy of this vector, bound by cube.

Return type

Vector

clamped_size(min, max) Vector

Create a copy of this vector, with its magnitude/size/length clamped between Min and Max.

Parameters
  • min (double) –

  • max (double) –

Return type

Vector

clamped_size2d(min, max) Vector

Create a copy of this vector, with the 2D magnitude/size/length clamped between Min and Max. Z is unchanged.

Parameters
  • min (double) –

  • max (double) –

Return type

Vector

clamped_size_max(max) Vector

Create a copy of this vector, with its maximum magnitude/size/length clamped to MaxSize.

Parameters

max (double) –

Return type

Vector

clamped_size_max2d(max) Vector

Create a copy of this vector, with the maximum 2D magnitude/size/length clamped to MaxSize. Z is unchanged.

Parameters

max (double) –

Return type

Vector

cosine_angle2d(b) double

Returns the cosine of the angle between this vector and another projected onto the XY plane (no Z).

Parameters

b (Vector) – the other vector to find the 2D cosine of the angle with.

Returns

The cosine.

Return type

double

cross(b) Vector

Returns the cross product of two 3d vectors - see http://mathworld.wolfram.com/CrossProduct.html

Parameters

b (Vector) –

Return type

Vector

direction_unit_to(to) Vector

Find the unit direction vector from one position to another or (0,0,0) if positions are the same.

Parameters

to (Vector) –

Return type

Vector

distance(v2) double

Distance between two points.

Parameters

v2 (Vector) – The second point.

Returns

The distance between two points.

Return type

double

distance2d(v2) double

Euclidean distance between two points in the XY plane (ignoring Z).

Parameters

v2 (Vector) – The second point.

Returns

The distance between two points in the XY plane.

Return type

double

distance2d_squared(v2) double

Squared euclidean distance between two points in the XY plane (ignoring Z).

Parameters

v2 (Vector) – The second point.

Returns

The distance between two points in the XY plane.

Return type

double

distance_squared(v2) double

Squared distance between two points.

Parameters

v2 (Vector) – The second point.

Returns

The squared distance between two points.

Return type

double

divide(b=[1.000000, 1.000000, 1.000000]) Vector

Element-wise Vector division (Result = {A.x/B.x, A.y/B.y, A.z/B.z})

Parameters

b (Vector) –

Return type

Vector

divide_float(b=1.000000) Vector

Vector divide by a float

Parameters

b (double) –

Return type

Vector

divide_int(b=1) Vector

Vector divide by an integer

Parameters

b (int32) –

Return type

Vector

dot(b) double

Returns the dot product of two 3d vectors - see http://mathworld.wolfram.com/DotProduct.html

Parameters

b (Vector) –

Return type

double

equals(b) bool

Returns true if vector A is equal to vector B (A == B)

Parameters

b (Vector) –

Return type

bool

get_abs() Vector

Get a copy of this vector with absolute value of each component.

Returns

A copy of this vector with absolute value of each component.

Return type

Vector

get_abs_max() double

Find the maximum absolute element (abs(X), abs(Y) or abs(Z)) of a vector

Return type

double

get_abs_min() double

Find the minimum absolute element (abs(X), abs(Y) or abs(Z)) of a vector

Return type

double

get_max(b) Vector

Find the maximum elements (X, Y and Z) between the two vector’s components

Parameters

b (Vector) –

Return type

Vector

get_max_element() double

Find the maximum element (X, Y or Z) of a vector

Return type

double

get_min(b) Vector

Find the minimum elements (X, Y and Z) between the two vector’s components

Parameters

b (Vector) –

Return type

Vector

get_min_element() double

Find the minimum element (X, Y or Z) of a vector

Return type

double

get_projection() Vector

Projects 2D components of vector based on Z.

Returns

Projected version of vector based on Z.

Return type

Vector

get_sign_vector() Vector

Get a copy of the vector as sign only. Each component is set to +1 or -1, with the sign of zero treated as +1.

Return type

Vector

heading_angle() double

Convert a direction vector into a ‘heading’ angle.

Returns

‘Heading’ angle between +/-PI radians. 0 is pointing down +X.

Return type

double

interp_spring_to(target, spring_state, stiffness, critical_damping_factor, delta_time, mass=1.000000, target_velocity_amount=1.000000, clamp=False, min_value=[-1.000000, -1.000000, -1.000000], max_value=[1.000000, 1.000000, 1.000000], initialize_from_target=False) -> (Vector, spring_state=VectorSpringState)

Uses a simple spring model to interpolate a vector from Current to Target.

Parameters
  • target (Vector) – Target value

  • spring_state (VectorSpringState) – Data related to spring model (velocity, error, etc..) - Create a unique variable per spring

  • stiffness (float) – How stiff the spring model is (more stiffness means more oscillation around the target value)

  • critical_damping_factor (float) – How much damping to apply to the spring (0 means no damping, 1 means critically damped which means no oscillation)

  • delta_time (float) – Time difference since the last update

  • mass (float) – Multiplier that acts like mass on a spring

  • target_velocity_amount (float) – If 1 then the target velocity will be calculated and used, which results following the target more closely/without lag. Values down to zero (recommended when using this to smooth data) will progressively disable this effect.

  • clamp (bool) – Whether to use the Min/Max values to clamp the motion

  • min_value (Vector) – Clamps the minimum output value and cancels the velocity if it reaches this limit

  • max_value (Vector) – Clamps the maximum output value and cancels the velocity if it reaches this limit

  • initialize_from_target (bool) – If set then the current value will be set from the target on the first update

Returns

spring_state (VectorSpringState): Data related to spring model (velocity, error, etc..) - Create a unique variable per spring

Return type

VectorSpringState

interp_to(target, delta_time, interp_speed) Vector

Tries to reach Target based on distance from Current position, giving a nice smooth feeling when tracking a position.

Parameters
  • target (Vector) – Target position

  • delta_time (float) – Time since last tick

  • interp_speed (float) – Interpolation speed, if the speed given is 0, then jump to the target.

Returns

New interpolated position

Return type

Vector

interp_to_constant(target, delta_time, interp_speed) Vector

Tries to reach Target at a constant rate.

Parameters
  • target (Vector) – Target position

  • delta_time (float) – Time since last tick

  • interp_speed (float) – Interpolation speed

Returns

New interpolated position

Return type

Vector

is_nan() bool

Determines if any component is not a number (NAN)

Returns

true if one or more components is NAN, otherwise false.

Return type

bool

is_near_equal(b, error_tolerance=0.000100) bool

Returns true if vector A is equal to vector B (A == B) within a specified error tolerance

Parameters
Return type

bool

is_nearly_zero(tolerance=0.000100) bool

Checks whether vector is near to zero within a specified tolerance.

Parameters

tolerance (float) – Error tolerance.

Returns

true if vector is in tolerance to zero, otherwise false.

Return type

bool

is_normal() bool

Determines if vector is normalized / unit (length 1).

Returns

true if normalized, false otherwise.

Return type

bool

is_not_near_equal(b, error_tolerance=0.000100) bool

Returns true if vector A is not equal to vector B (A != B) within a specified error tolerance

Parameters
Return type

bool

is_uniform(tolerance=0.000100) bool

Checks whether all components of this vector are the same, within a tolerance.

Parameters

tolerance (float) – Error tolerance.

Returns

true if the vectors are equal within tolerance limits, false otherwise.

Return type

bool

is_unit(squared_lenth_tolerance=0.000100) bool

Determines if vector is normalized / unit (length 1) within specified squared tolerance.

Parameters

squared_lenth_tolerance (float) –

Returns

true if unit, false otherwise.

Return type

bool

is_zero() bool

Checks whether all components of the vector are exactly zero.

Returns

true if vector is exactly zero, otherwise false.

Return type

bool

length() double

Returns the length of the vector

Return type

double

length2d() double

Returns the length of the vector’s XY components.

Return type

double

length2d_squared() double

Returns the squared length of the vector’s XY components.

Return type

double

length_squared() double

Returns the squared length of the vector

Return type

double

lerp_to(b, alpha) Vector

Linearly interpolates between A and B based on Alpha (100% of A when Alpha=0 and 100% of B when Alpha=1)

Parameters
Return type

Vector

linear_color() LinearColor

Converts a vector to LinearColor

Return type

LinearColor

mirror_by_plane(plane) Vector

Mirrors a vector about a plane.

Parameters

plane (Plane) –

Returns

Mirrored vector.

Return type

Vector

mirror_by_vector(surface_normal) Vector

Given a direction vector and a surface normal, returns the vector reflected across the surface normal. Produces a result like shining a laser at a mirror!

Parameters

surface_normal (Vector) – A normal of the surface the ray should be reflected on.

Returns

Reflected vector.

Return type

Vector

multiply(b) Vector

Element-wise Vector multiplication (Result = {A.x*B.x, A.y*B.y, A.z*B.z})

Parameters

b (Vector) –

Return type

Vector

multiply_float(b) Vector

Scales Vector A by B

Parameters

b (double) –

Return type

Vector

multiply_int(b) Vector

Scales Vector A by B

Parameters

b (int32) –

Return type

Vector

negated() Vector

Negate a vector.

Return type

Vector

normal(tolerance=0.000100) Vector

Gets a normalized unit copy of the vector, ensuring it is safe to do so based on the length. Returns zero vector if vector length is too small to safely normalize.

Parameters

tolerance (float) – Minimum squared vector length.

Returns

A normalized copy if safe, (0,0,0) otherwise.

Return type

Vector

normal2d(tolerance=0.000100) Vector

Gets a normalized unit copy of the 2D components of the vector, ensuring it is safe to do so. Z is set to zero. Returns zero vector if vector length is too small to normalize.

Parameters

tolerance (float) – Minimum squared vector length.

Returns

Normalized copy if safe, (0,0,0) otherwise.

Return type

Vector

normal_unsafe() Vector

Calculates normalized unit version of vector without checking for zero length.

Returns

Normalized version of vector.

Return type

Vector

normalize(tolerance=0.000000) None

Normalize this vector in-place if it is large enough or set it to (0,0,0) otherwise.

Parameters

tolerance (float) – Minimum squared length of vector for normalization.

not_equal(b) bool

Returns true if vector A is not equal to vector B (A != B)

Parameters

b (Vector) –

Return type

bool

project_on_to(target) Vector

Projects one vector (V) onto another (Target) and returns the projected vector. If Target is nearly zero in length, returns the zero vector.

Parameters

target (Vector) – Vector on which we are projecting.

Returns

V projected on to Target.

Return type

Vector

project_on_to_normal(normal) Vector

Gets a copy of this vector projected onto the input vector, which is assumed to be unit length.

Parameters

normal (Vector) – Vector to project onto (assumed to be unit length).

Returns

Projected vector.

Return type

Vector

project_on_to_plane(plane_normal) Vector

Projects a vector onto a plane defined by a normalized vector (PlaneNormal).

Parameters

plane_normal (Vector) – Normal of the plane.

Returns

Vector projected onto the plane.

Return type

Vector

project_point_on_to_plane(plane_base, plane_normal) Vector

Projects/snaps a point onto a plane defined by a point on the plane and a plane normal.

Parameters
  • plane_base (Vector) – A point on the plane.

  • plane_normal (Vector) – Normal of the plane.

Returns

Point projected onto the plane.

Return type

Vector

quaternion() Quat

Return the Quaternion orientation corresponding to the direction in which the vector points. Similar to the FRotator version, returns a result without roll such that it preserves the up vector. note: If you don’t care about preserving the up vector and just want the most direct rotation, you can use the faster ‘FQuat::FindBetweenVectors(FVector::ForwardVector, YourVector)’ or ‘FQuat::FindBetweenNormals(…)’ if you know the vector is of unit length.

Returns

Quaternion from the Vector’s direction, without any roll.

Return type

Quat

random_point_in_box_extents(half_size) Vector

Returns a random point within the specified bounding box using the first vector as an origin and the second as the box extents.

Parameters

half_size (Vector) –

Return type

Vector

reciprocal() Vector

Gets the reciprocal of this vector, avoiding division by zero. Zero components are set to BIG_NUMBER.

Returns

Reciprocal of this vector.

Return type

Vector

rotate(b) Vector

Returns result of vector A rotated by Rotator B

Parameters

b (Rotator) –

Return type

Vector

rotate_angle_axis(angle_deg, axis) Vector

Returns result of vector A rotated by AngleDeg around Axis

Parameters
Return type

Vector

rotator() Rotator

Return the FRotator orientation corresponding to the direction in which the vector points. Sets Yaw and Pitch to the proper numbers, and sets Roll to zero because the roll can’t be determined from a vector.

Returns

FRotator from the Vector’s direction, without any roll.

Return type

Rotator

rotator_from_axis_and_angle(angle) Rotator

Create a rotation from an this axis and supplied angle (in degrees)

Parameters

angle (float) –

Return type

Rotator

set(x, y, z) None

Set the values of the vector directly.

Parameters
  • x (double) –

  • y (double) –

  • z (double) –

snapped_to_grid(grid_size) Vector

Gets a copy of this vector snapped to a grid.

Parameters

grid_size (float) – Grid dimension / step.

Returns

A copy of this vector snapped to a grid.

Return type

Vector

subtract(b) Vector

Vector subtraction

Parameters

b (Vector) –

Return type

Vector

subtract_float(b) Vector

Subtracts a float from each component of a vector

Parameters

b (double) –

Return type

Vector

subtract_int(b) Vector

Subtracts an integer from each component of a vector

Parameters

b (int32) –

Return type

Vector

to_degrees() Vector

Converts a vector containing radian values to a vector containing degree values.

Returns

Vector containing degree values

Return type

Vector

to_radians() Vector

Converts a vector containing degree values to a vector containing radian values.

Returns

Vector containing radian values

Return type

Vector

transform() Transform

Convert a vector to a transform. Uses vector as location

Return type

Transform

truncated() IntVector

Rounds A to an integer with truncation towards zero for each element in a vector. (e.g. -1.7 truncated to -1, 2.8 truncated to 2)

Return type

IntVector

unit_cartesian_to_spherical() Vector2D

Converts a Cartesian unit vector into spherical coordinates on the unit sphere.

Returns

Output Theta will be in the range [0, PI], and output Phi will be in the range [-PI, PI].

Return type

Vector2D

unrotate(b) Vector

Returns result of vector A rotated by the inverse of Rotator B

Parameters

b (Rotator) –

Return type

Vector

unwind_euler() None

When this vector contains Euler angles (degrees), ensure that angles are between +/-180

vector2d() Vector2D

Convert a Vector to a Vector2D using the Vector’s (X, Y) coordinates

Return type

Vector2D

property x

[Read-Write] X

Type

(double)

property y

[Read-Write] Y: Alias for float/double depending on LWC status. Note: Will be refactored to double before UE5 ships.

Type

(double)

property z

[Read-Write] Z

Type

(double)