Introduction to TransformHandle API
Introduction to the TransformHandle API and the key differences from the Transform API.
Read time 3 minutesLast updated 12 days ago
The API is an alternative to the API. Unlike the component (a managed class), is an unmanaged , which makes it compatible with the Burst compiler in code that runs on the main thread.
TransformHandleTransformTransformTransformHandlestructWhile the API covers the same core operations as the API, its design introduces several key differences described on this page. The API ensures compatibility with future entity and GameObject interactions.
TransformHandleTransformTransformHandleDifferences with Transform API
The API functionality is equivalent to the API, the key differences are in the way you access it, and in the implementation details. The API works alongside the API in Unity 6.
TransformHandleTransformTransformHandleTransformTransform API (Unity 6.2 and earlier) | TransformHandle API (Unity 6.3 and later) |
|---|---|
You access the transform using the | You access the transform using |
Returns a | Returns a |
| The API is managed and not compatible with the Burst compiler. | Is compatible with the Burst compiler in Burst-compiled code that runs on the main thread. The |
| Editor and runtime API. | Runtime-only API. |
Transform APIs that are not available in the TransformHandle API
The following methods and properties from APIs are not available in API:
TransformTransformHandle- /
GetSiblingIndexSetSiblingIndex Find- property
hasChanged
TransformHandle API without an equivalent in the Transform API
The following API elements don't have an equivalent in the API.
TransformHandleTransform-
represents an enumerable of the direct children of a transformHandle, and this enumerable returns a DirectChildrenEnumerator when enumerated.
TransformHandle.DirectChildrenEnumerable -
is an enumerator that goes through the direct children of a transform.
TransformHandle.DirectChildrenEnumerator -
returns a DirectChildrenEnumerable of this transform, which you can use to iterate over direct children with a foreach loop.
TransformHandle.DirectChildren -
returns a DirectChildrenEnumerator of this transform, which you can use to manually iterate over direct children.
TransformHandle.GetDirectChildrenEnumerator -
represents an enumerable of a
TransformHandle.SubhierarchyEnumerableinstance and all of its descendants. When enumerated, it returns aTransformHandleinstance.TransformHandle.SubhierarchyEnumerator -
is an enumerator that yields a
TransformHandle.SubhierarchyEnumeratorinstance and all of its descendants. TheTransformHandleinstance itself is yielded first, followed by its descendants in depth-first order.TransformHandle -
returns a
TransformHandle.Subhierarchyinstance that you can use to iterate over thisTransformHandle.SubhierarchyEnumerableinstance and all of its descendants with aTransformHandleloop.foreach -
returns a
TransformHandle.GetSubhierarchyEnumeratorinstance that you can use to manually iterate over thisTransformHandle.SubhierarchyEnumeratorinstance and all of its descendants.TransformHandle
Differences in common operations
The following common operations have a different implementation in API.
TransformHandleCheck if a transform is valid:
- Transform:
transform != null - TransformHandle:
TransformHandle.IsValid
Iterate the direct children of the transform:
- Transform:
foreach (Transform t in transform) - TransformHandle:
foreach (TransformHandle t in handle.DirectChildren)
Set a parent of a transform to :
None-
Transform:
transform.SetParent(null) -
TransformHandle:
transformHandle.SetParent(TransformHandle.None)Alternative declaration:TransformHandle h = transformHandle; h.parent = TransformHandle.None;
For specific examples on how to use the API, refer to TransformHandle API examples.
Methods with different argument or return types
The following methods are functionally equivalent, but have different argument types or return types (, or depending on the API they are called from).
TransformTransformHandleDifferent argument types:
IsChildOfLookAtSetParent- (overload)
Translate
Different return types:
GetChildparentroot