A Unity object or component is looked up in Update, LateUpdate, FixedUpdate or OnGUI, once per frame

tx0/csharp:unity-lookup-every-framerecommendedwarningframeworks/unitydepth fastperformance

What it finds

GameObject.Find, FindObjectOfType, FindWithTag and GetComponent search the scene or the object every time they run; in a per-frame method that cost repeats dozens of times a second. Looking the object up once in Awake or Start and keeping it in a field avoids it. The rule applies to files that use UnityEngine.

From the rule's source, unity_lookup_every_frame.rs.

Example from the rule's tests
using UnityEngine; class Follow : MonoBehaviour{    private Transform target;     void Start()    {        target = GameObject.Find("Player").transform;    }     void Update()    {        var body = GetComponent<Rigidbody>();tx0 reports: GetComponent runs every frame in Update    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:unity-lookup-every-frame" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:unity-lookup-every-frame] reason="..."

tx0 explain tx0/csharp:unity-lookup-every-frame shows the same in the terminal. Found a false positive? Report it.