Can a transformation be applied to a PackedVector2Array

Godot Version

4.4-stable

Question

Is there a way to apply a global transform to a PackedVector2Array or do I have to manually loop through each vector in the array?

Second Question

What is more performant, looping through the PackedVector2Array or using map?

.map is likely more performant. You do have to go through to apply the transformation if the PackedVector2Array is the only data type you are dealing with. What’s the big picture issue? Why do you need to apply a transform to many vector2s?

I have two objects with PackedVector2Arrays. One is a CollisionPolygon2d and the other is a custom resource. They are both traveling through the world with their own transforms and their parent transforms. I want to use the Geometry Class to clip etc on these two PackedVector2Arrays. That means I will need to be able to transform them to the same relative coordinates.

2 Likes

As it turns out, packed arrays don’t have a map method.

Differences between packed arrays, typed arrays, and untyped arrays: Packed arrays are generally faster to iterate on and modify compared to a typed array of the same type (e.g. PackedVector2Array versus Array[Vector2]). Also, packed arrays consume less memory. As a downside, packed arrays are less flexible as they don’t offer as many convenience methods such as Array.map(). Typed arrays are in turn faster to iterate on and modify than untyped arrays.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.