Confusion about FindGameObjectWithTag and FindWithTag

Hey there folks.

I just noticed something pretty weird about Unity. There are 2 ways to find an GameObject by Tag. FindWithTag and FindGameObjectWithTag. I was asking myself what the differences could be so I checked the documentation. But there was the first weird thing I noticed. Only FindWithTag has a documentation entry. FindGameObjectWithTag doesn’t. Then I got really curious about that and jumped to declaration to see if I can spot differences there. And yes I did.
Thats the snippet I get when jumping to declaration:

        [WrapperlessIcall]
        [MethodImpl (MethodImplOptions.InternalCall)]
        public static extern GameObject FindGameObjectWithTag (string tag);

        public static GameObject FindWithTag (string tag)
        {
            return GameObject.FindGameObjectWithTag (tag);
        }

And it turned out that FindWithTag simply calls FindGameObjectWithTag. Which I assume is some native/c++ way to find the object as it uses the extern keyword.

My question is why Unity has 2 methods for doing the same thing. And one of the methods is just calling the other and returning the result. So they are the same. Why not only have FindGameObjectWithTag? And remove FindWithTag?

Any speculations or definite answers on that?

1 Like

Maybe this is a bug? they probably wanted to hide the extern call (make it private) so you access it through a managed (C#) API. That way they can change the implementation later on without you relying on it. Just a guess though…

Possibly a mistake as @litoral suggested. Another possibility is that they wanted to make it more explicit and thus added FindGameObjectWithTag(…), but also didn’t want to break backwards compatibility and only removed FindWithTag(…) from the docs. It could be that it’s on its way to being deprecated and, ultimately, removed some time in the future.