Is CompareTag better than gameObject.tag performance wise?

Operator comparison will create one more string object, which is to be deleted very soon and that makes it generation 0 on the heap. Microsoft claims garbage collector is blazingly fast on gen0 for .NET Framework, but I don’t know the situation for Mono.

As a veteran software developer I would recommend ignoring such micro optimizations unless it is called more than a hundred times per frame. I think such optimizations are in the category of compiler optimizations.

Now time for shameless marketing :slight_smile: Code Enchanter automatically converts all of your tag operator comparisons to method comparisons from your source code.

For example myObject.tag == “myTag” to myObject.CompareTag(“myTag”)

It has some other performance tricks as well, it’s available on Code Enchanter | Utilities Tools | Unity Asset Store