Toggling a gameobject active with button On click

I am trying to toggle a game object active with a button this script On Click:

public void toggleFrogHelmet()
{
frogHelmet.SetActive (!frogHelmet.activeSelf);
Debug.Log(“toggle”);
}

I get the Debug Log but the gameobject does not toggle setActive to true or false. I have also tried activeInHierarchy with the same results. Google searched a bunch but this seems to be the repeating answer so what am I doing wrong?

Check out the code formatting post, first one in the forum.

What value to do you see for frogHelmet.activeSelf if you print that along with your Debug.Log() call? Does it change each time you press it?

Hello Kurt, it keeps returning false

if it is returning false, the game object should be disappearing but it is not… I am so confused

Are you sure you have the gameObject that you actually instantiated in the scene and NOT the prefab you instantiated it from?

yes, in my shop control script (which is attached to the shop control gameobject which is where I’m getting the toggleFrogHelmet script) I have the game object frogHelmet which I dragged from the scene

I’m trying to make a UI dialog invisible, in-game, upon a button click also using a “setActive(false)” call.

I’ve done this successfully multiple times in my game but for some reason it is not working for this particular dialog I’m working on. I’ve noticed that while the game is running, I can’t even uncheck the “Active” checkbox in the Inspector tab. So no wonder my code calling “setActive(false)” isn’t working.

Has anyone ever seen this before, where clicking the “Active” checkbox for a GameObject in the Inspector does nothing? I can toggle this checkbox for my other dialogs but for this particular one clicking it does nothing.

This dialog started as a prefab and I’ve even unpacked the prefab completely and the behavior is still the same.

EDIT: I’m pretty sure it’s due to me having my game paused. It’s a “how to play” dialog that I want to come up when the user plays the game for the very first time. I have my game paused so it’s not running when the user is reading the dialog (there’s a countdown timer for gameplay) but it must be because I have the game paused that this “setActive(false)” call and the toggling of the Active checkbox in Inspector isn’t working. Well that’s nice but I have no idea how to solve it lol.

you cant interaction with Inspector, cuz the editor know it is being use by some script, some script some where on your code keep make it active

Your script and the editor interaction may be at odds with each other. I’ve seen this when I’m updating a slider on-screen via script continuously (like with a ramp or lerp), you can’t interact normally with the reflected one in the Inspector, because it keeps getting overwritten by the script.

Just tested pausing and setting an object active/inactive, that works fine, so it’s something with your script. Deactivate the script or comment out the line and try it maybe.