Cannot deactivate / activate gameobject, even in editor!

Hello,

I have a problem where one of my guns will not deactivate / activate when I switch to it. All of my other weapons will correctly activate / deactivate through my scripts, but just this one weapon refuses to do it!

The weird things is this though: I can’t even click on the active checkbox in the editor!

Here is a video showing what happens when I try to deactivate the gameobject → link to video

I have tried using gameobject.active = false, gameobject.SetActive(false), and also clicking the actual check box in the editor, but to no avail.

Also - I am not using GameObject.Find, or anything like that. The gameobject is referenced through a script, and is not null.

Someone help! Is it because of an animation possibly? Its not a referencing issue, because all my other weapons use the same weapon script and they deactivate / activate just fine. Nothing appears in the console log.

Thanks!
-Fuego

Ok, so this may seem weird , but I had the exact same problem although with a child Object whose parent had the animator component along with a script to control it. Even though the animation wasn’t playing, I couldn’t activate/deactivate the gameobject through a script or in the editor! Tried to fix this by setting the animator component to none, and I can control it again! So I copied the gameobject to an empty scene without a script and only an animator. Turns out the animator was creating the problem → Link To Video.

So, what I did was, I removed the IsActive property from the animation, and guess what? It started to work normally again → Link To Video.
I can fix my problem because i am working with a sprite, so I can set the opacity but if this comes up with a gameobject, I wouldn’t be able to do this.

Has this been fixed in the latest versions of Unity? I am currently using Unity 2019.3.0f6. Do I have to update the current version? Because I really don’t want to as I fear it will mess up my code.

when this annoyance happens to me it usually is that I have some Animation making it enabled. If you have this problem, and can not find the line of code which constantly enables that object, check the animations regarding that object.

when this annoyance happens to me it usually is that I have some little line of code in an update function making it stay on, or a value or another script that if it is “true” or enableld something is SetActive. I fix it by changing something in that script to generate an error saying such and such script is now broken . This way I locate what script is keeping that object SetActive (true)

Well, you most likely have a script somewhere that is constantly setting it to active. Yes, it’s possible that you have created an animation which constantly setting it to active. However from the information given we can’t tell.

@Bunny83 may be right or something else requires that component in order to play

This can also happen if you’re inside of a prefab, and the Game Object you’re trying to deactivate was activated outside of the prefab as an override. To fix, back out of the prefab, revert the active checkbox. Then when you go back in the prefab you can change it’s active state again.