How to access an inactive gameObject with tag

Hello. I have a gameObject called playerWeaponsPrefab which has 4 children, the first child is tagged as PrimaryWeapon, the second is tagged as SecondaryWeapon, the third is tagged as Knife and the forth is a grenade, I want to select these weapons in game by pressing 1,2,3 and 4 buttons ( while a weapon is selected others must be inactive). I put these weapon gameObjects in 4 variables and used GameObject.FindwithTag(exampleWeapon) for accessing to them but I can not access to them and it returns null because the gameObject is not active. I was shocked when I saw GameObject.FindWithTag doesn’t work on inactive Objects. what Should I do to access my inactive weapon? thanks for help in advance.

Leave them enabled in the editor, get them with Start() and after you have them disable them.

You could also try making 4 public gameObjects and just drag your weapons in there.

private void Start()
	{
		weapon = GameObject.FindGameObjectWithTag("tag");
		weapon.SetActive (false);
	}

You should have a pre-defined array with the weapons or a list if you want to add more in the future, i think it’s better than always using any GameObject.Find

I know this is an old thread, but i stumble over tihis problem once in a while. My best practice is to have a top object with the tag and only deactivate the the child(s).