GameObject.SetActive(true) not working?

hi! im beginner to Unity and i couldnt solve the problem. the false command works but true does not. im sure i assigned the objects correctly what should i do? :pleading_face:

public GameObject square;

void Start()
{

}

void Update()
{
    if (Input.GetKeyDown(KeyCode.K))
    {
        square.SetActive(false);
    }
    if (Input.GetKeyDown(KeyCode.A))
    {
        square.SetActive(true);
    }
}

Hello @yuunamis,

If the gameObject you are deactivating is the one holding the script then it will not work because the Update loop is only active when the gameObject is active.

thanks for answer! so i should put this code into another function or add other objects to the scene. did i get right :confused:

okay i understand, the problem was solved when i assigned the code to a constantly running object. thanks! :innocent: