Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 803 Bytes

File metadata and controls

36 lines (27 loc) · 803 Bytes

UNT0036 Inefficient method to get position and rotation

Accessing the Transform/TransformAccess should be done as few times as possible for performance reasons. Instead of reading position and rotation sequentially, you should use GetPositionAndRotation() method.

Examples of patterns that are flagged by this analyzer

using UnityEngine;

class Camera : MonoBehaviour
{
    void Update()
    {
        var position = transform.position;
        var rotation = transform.rotation;
    }
}

Solution

Fix assignment:

using UnityEngine;

class Camera : MonoBehaviour
{
    void Update()
    {
        transform.GetPositionAndRotation(out var position, out var rotation);
    }
}

A code fix is offered for this diagnostic to automatically apply this change.