UNT0037 Inefficient method to get localPosition and localRotation
June 17, 2025 ยท View on GitHub
Accessing the Transform/TransformAccess should be done as few times as possible for performance reasons. Instead of reading localPosition and localRotation sequentially, you should use GetLocalPositionAndRotation() method.
Examples of patterns that are flagged by this analyzer
using UnityEngine;
class Camera : MonoBehaviour
{
void Update()
{
var localPosition = transform.localPosition;
var localRotation = transform.localRotation;
}
}
Solution
Fix assignment:
using UnityEngine;
class Camera : MonoBehaviour
{
void Update()
{
transform.GetLocalPositionAndRotation(out var localPosition, out var localRotation);
}
}
A code fix is offered for this diagnostic to automatically apply this change.