docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method ComputeWorldTransformMatrix

    ComputeWorldTransformMatrix(in Entity, out float4x4, ref ComponentLookup<LocalTransform>, ref ComponentLookup<Parent>, ref ComponentLookup<PostTransformMatrix>)

    Synchronously compute a local-to-world transformation matrix for an entity, using the current values of LocalTransform and PostTransformMatrix for the target entity and its hierarchy ancestors.

    Declaration
    [BurstCompile]
    [GenerateTestsForBurstCompatibility]
    public static void ComputeWorldTransformMatrix(in Entity entity, out float4x4 outputMatrix, ref ComponentLookup<LocalTransform> localTransformLookup, ref ComponentLookup<Parent> parentLookup, ref ComponentLookup<PostTransformMatrix> scaleLookup)
    Parameters
    Type Name Description
    Entity entity

    The entity whose world-space transform should be computed.

    float4x4 outputMatrix

    If successful, the output world-space transformation matrix will be stored here.

    ComponentLookup<LocalTransform> localTransformLookup

    Required to access the current transform values for entity and its ancestors in the transform hierarchy. This method only requires read-only access.

    ComponentLookup<Parent> parentLookup

    Required to access the current parent for entity and its ancestors in the transform hierarchy. This method only requires read-only access.

    ComponentLookup<PostTransformMatrix> scaleLookup

    Required to access the current non-uniform scale values for entity and its ancestors in the transform hierarchy. This method only requires read-only access.

    Remarks

    This method is intended for the relatively uncommon cases where an entity's accurate world-space transformation matrix is needed immediately. For example:

    • When performing a raycast from an entity which may be part of an entity hierarchy, such as the wheel of a car object. The ray origin must be in world-space, but the entity's LocalTransform may be relative to its parent.
    • When one entity's transform needs to "track" another in world-space, and the targeting entity and/or the targeted entity are in a transform hierarchy.
    • When an entity's transform is modified in the LateSimulationSystemGroup (after the TransformSystemGroup has updated, but before the PresentationSystemGroup runs), this method can be used to compute a new LocalToWorld value for the affected entity.

    For an entity that is not part of an entity hierarchy, the LocalTransform component already stores the world-space transform (since the two spaces are identical). In his case, reading LocalTransform directly is more efficient than calling this method.

    The LocalToWorld component also contains a world-space transformation matrix. However, this value may be out of date or invalid; it is only updated when the TransformSystemGroup runs). It may also contain additional offsets applied for graphical smoothing purposes. Therefore, while the LocalToWorld component may be useful as a fast approximation when its latency is acceptable, it should not be relied one when an accurate, up-to-date world transform is needed for simulation purposes.

    This method's running time scales with the depth of the target entity is in its hierarchy.

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if entity or one if its ancestors are invalid, or are missing the required LocalTransform component.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)