Issue using GameObject.Find / GameObject.FindGameObjectWithTag

I am making a system where using the name of the first object in the list it will find the gameobject with that name/tag and show it/set it active. Here is the code for that

void GetCat()
{
    ActiveCat = CurrentParty[0];
    FirstCat = GameObject.FindGameObjectWithTag(ActiveCat);
    FirstCat.SetActive(true);
}

I have tested it and ActiveCat does return the correct value, however FirstCat always returns null. I have tags that match the names or the gameobject and the names in the list perfectly and I have check all of those. ActiveCat is a public string, and FirstCat is a public gameobject that never ends up with the object assigned to it. Is there something wrong with my use of find or gameobjects?

An example of what happens:
Lets say the first cat of the list is “Charmine”


image
(Charmine is a sprite)
here is what happens
image
image

Ooh, don’t do that… we have better ways of connecting things directly!!! See below.

Remember the first rule of GameObject.Find():

Do not use GameObject.Find();

More information: https://starmanta.gitbooks.io/unitytipsredux/content/first-question.html

In general, DO NOT use Find-like or GetComponent/AddComponent-like methods unless there truly is no other way, eg, dynamic runtime discovery of arbitrary objects. These mechanisms are for extremely-advanced use ONLY.

If something is built into your scene or prefab, make a script and drag the reference(s) in. That will let you experience the highest rate of The Unity Way™ success of accessing things in your game.

“Stop playing ‘Where’s GameWaldo’ and drag it in already!”

Here’s why all this “Find” stuff is CRAZY code:

The issue is that I cannot do that without using a bunch of if statements and clogging up the code. I need to get the first item in the list, which can be 1 of 10 items. Unless there is a simpler way to do that I will need a way to use find or something similar.

GameObject.FindGameObjectWithTag only returns active game objects. However, based on your screenshot, it appears that the game objects in question are inactive.

You are so right, thank you

Are these game objects all in the same scene as the cats (which all have great names, btw)? It would be easier to reference them directly via the inspector, likely in a collection. If they all have a common component as well, better to reference them via said component.