Why does SetActive(true) not work on child?

Inside my player, I have a child called Miniturret. I want this to be an upgrade therefore I did SetActive(false) at the start of the game. But when I try to use SetActive(true) it doesn’t work?
Note that SetActive(false) does work:
Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpgradeController : MonoBehaviour
{
    //private int cash;
    public int TurretCost;
    private GameObject mainTurret;

    private void Start()
    {
        //transform.Find("MiniTurre t").gameObject.SetActive(false);
        GameObject mainTurret = GameObject.Find("MiniTurret");
        mainTurret.SetActive(false);
    }

    public void TurretUpgrade()
    { 
        //print(GameObject.FindGameObjectWithTag("Player").GetComponent<Currency>().plrCurrency);
        if (TurretCost <= GameObject.FindGameObjectWithTag("Player").GetComponent<Currency>().plrCurrency)
        {
            print("SUb");
            // Add turret
            mainTurret.SetActive(true);
            GameObject.FindGameObjectWithTag("Player").GetComponent<Currency>().RemoveCurrency(TurretCost);
        }
    }
}

Hello.

First, i don’t recommend to use GameOnject.Find(). As it consumes a lot of memeory, is better to tag the turret and use GameObject.FindGameObjectWithTag() or if the turret is a child of player, do Player.transform.Find() ot player.transform.GetChild()

Then about your problem, the problem is that you declare 2 different vaaraibles called mainTurret

public class UpgradeController : MonoBehaviour
 {
     private GameObject mainTurret;    <- Here you declaring a mainturret for all UpgradeController  script
 
     private void Start()
     {
         GameObject mainTurret = GameObject.Find("MiniTurret");  // But Here you are declaring a new mainturret for the Start function, and defining this mainturret, not the general fromt he script.

         mainTurret.SetActive(false);  //So you disable this mainturret
     }

     // In all other functiuons mainturret refears to the general mainturret (which is null because you only defined the Start().mainturret

Solution:

 private void Start()
     {
         //transform.Find("MiniTurre t").gameObject.SetActive(false);
         mainTurret = GameObject.Find("MiniTurret");  // < Removed "GameObject" word, so this is not a declaration of a new variable, this is a reference to the mainturret existing variable.
         mainTurret.SetActive(false);
     }

Bye!