A Unity tag is compared as a string, which allocates, where CompareTag does not
What it finds
Reading gameObject.tag copies the tag into a new string each time; CompareTag("Player") compares without allocating and reports unknown tags.
From the rule's source, unity_tag_compared_as_string.rs.
using UnityEngine; class Pickup : MonoBehaviour{ void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Player")tx0 reports: the tag is compared as a string { } if (other.CompareTag("Player")) { } }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:unity-tag-compared-as-string" = "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-tag-compared-as-string] reason="..."tx0 explain tx0/csharp:unity-tag-compared-as-string shows the same in the terminal. Found a false positive? Report it.