How can I use SetActive(false) on the object itself?

I need to make an object diaappear, but not destroyed because I need it later. Normally I would use


which works fine, providing of course that anObject is an instance.

So surely the way to do this in a script on the object itself is:


But this doesn’t work. Do I really have to use GameObject.Find() to find itself?

hi, Im not so good at programming but i have an idea try this:
declare a new public game object var and put you object itself in inspector. I know it’s not the best way but i think it’s still helpfull

Just an update, gameObject.SetActive(false) DOES work, but my problem was that I hadn’t referenced the gameController script correctly and the script was bombing before it even got to this line