GameObject setActive() won't work

Hello everyone,

My question is probably really easy to solve but I can’t seem to find it…

  • I have a list with GameObjects
  • Through inspector I add weapons to the list
  • In the Start() method i set them all on false

Here is my error: I doesn’t set them to false… They are still visible when I run the game.

Code:

    public GameObject[] weaponList;

    void Start()
    {
        foreach (GameObject weapon in weaponList)
        {
            weapon.SetActive(false);
        }
    }

Pictures for better overview:
My hierarchy:

alt text

Script on Weapon Manager:

alt text

When you disable any gameobject only that game object will get deactivated. You have to deactivate all of the child gameobjects recursively if you want to completely.

In your case, this might be due dependency errors as others mentioned. make sure you’re not referencing these gameobjects anywhere in you code or scene. And make required changes accordingly.