TransformExtensions

Extension methods for UnityEngine.Transform that provide parent hierarchy traversal and Pose convenience accessors.

Definition

Namespace: Paragon Assembly: Paragon.dll

public static class TransformExtensions

Quick Lookup

Goal
Method

Walk up the parent chain

transform.GetParents()

Include self in parent walk

transform.GetParents(includeSelf: true)

Get position + rotation as Pose

transform.GetPose()

Set position + rotation from Pose

transform.SetPose(pose)

Methods

GetParents

Returns a lazy iterator over all parent transforms of the given transform, walking up the hierarchy from the immediate parent to the root.

public static IEnumerable<Transform> GetParents(this Transform transform, bool includeSelf = false)
Parameter
Type
Description

transform

Transform

The starting transform

includeSelf

bool

If true, yields the transform itself first before walking parents. Defaults to false.

Returns: An IEnumerable<Transform> yielding parents from nearest to root.

circle-info

Uses yield return for lazy evaluation — the hierarchy is only traversed as far as the caller iterates. Useful with LINQ operations like First(), Any(), or Where().

GetPose

Returns the world-space position and rotation of the transform as a Pose struct.

Returns: A Pose containing transform.position and transform.rotation.

SetPose

Sets the world-space position and rotation of the transform from a Pose struct.

Parameter
Type
Description

transform

Transform

The target transform

pose

Pose

The pose containing the new position and rotation

Calls transform.SetPositionAndRotation(pose.position, pose.rotation) internally for a single-call position and rotation update.

Examples

Finding an ancestor

Saving and restoring a pose

See Also

Last updated