Math with NumPy¶
How are vectors and transforms represented?
Reflected vector, integer vector and point, rotator, quaternion and plane values return NumPy arrays of the
matching dtype. Matrices and transforms return 4 x 4 arrays. Geometry and state structs such as Box remain
ue struct values.
import numpy as np
location = actor.get_actor_location() # ndarray, shape (3,)
actor.set_actor_location(location + np.array([0.0, 0.0, 100.0]), False, True)
Methods and writable properties accept arrays (or array-likes) as well as ue.Vector and the other wrappers.
Rules¶
- Arrays returned from Unreal are copies. Edit one and assign it back, or pass it to a setter.
- Transforms use Unreal's row-vector layout: translation is in
array[3, :3]. Matrix input must have shape(4, 4); transform input must be affine and representable without shear. - A matrix cannot carry rotation on an axis scaled to zero. To keep it, build a
ue.Transform(rotation,translation,scale3d) and pass that. - In sets and as map keys, these values read as tuples (a
TSet<FIntPoint>reads asset[tuple[int, int]]).
Type aliases¶
ue.numpy_types has aliases such as Vector3f64 and Matrix4x4f64:
from ue.numpy_types import Vector3f64
def move(position: Vector3f64) -> None: ...
Many objects at once¶
ue.batch_math calls a parameterless pure native getter on every object and returns one array:
locations = ue.batch_math(ue.Actor.get_actor_location, actors) # shape (len(actors), 3)
NumPy versions¶
Supported runtime: numpy>=2.0.0,<3. NumPy 1.x is not supported.