transform child out of bounds

hi all. So im running into some issues. basically I am trying to check it the character has a pistol equip. then if there is one hasPistol should be set to true in the animation controller. and if not do a regular walk animation and set hasPistol to false. I know why im having this problem which is because the equipment menu is hidden so i cant use FindGameObject to find the slot that the weapon is equipped to. So im trying to use transform.GetChild(x) to locate it in the hierarchy but for some reason i keep getting a error. transform child out of bounds. the error is on line 88.

oh i should mention that when the weapon is equipped it is assigned to slot 6. on the equipment menu.

I used Inventory Master which can be found on the asset store.

can anyone point me in the right direction?

I had something similar. It turned out that I could not turn the child object on by calling the deactivated child and doing SetActive(true). I had to find it’s parent and then turn on all of the children from the parent, or a selected child if you know what it’s index is. Here is the script that I use to do the job. I probably don’t need the search path in the Find., but it works fine.

    public void playerRight_Inventory_ShowHide(bool state){
        GameObject pi = GameObject.Find ("Canvas/PlayerRInventory");
        int count = pi.transform.childCount; // get the child count

        for(int i = 0; i < count; i++){ /
            pi.transform.GetChild(i).gameObject.SetActive(state);
        }
    }

One solution is to have the gameobject you wish to reference enabled, and disable it at run time via script. This means that other scripts can store their references, and it will keep them in memory even when the object is disabled

I have this same issue.
"
UnityException: Transform child out of bounds
PlayerScript.CreateAtStart (Int32 amount) (at Assets/Walls/Scripts/PlayerScript.cs:297)
PlayerScript.Start () (at Assets/Walls/Scripts/PlayerScript.cs:66"

line 66:

CreateAtStart (10);

Line 297:

tmp.transform.position = currentTileX[currentTileX.Count - 1].transform.GetChild(1).transform.position;

All of the children are present and accounted for and are attached to the proper parents.
The project ran fine in past versions of unity.
Is it possible that unity has changed how it handles this type of operation from version to version?

Hey Guys i may have the same Problem i just dont know how to fix it… (I am just trying to run a basic 2D EndlessRunner and my Background script always gives me this Error when a new Obstacle spawns) →

UnityException: Transform child out of bounds
Background.ResetObstacle () (at Assets/Background.cs:46)
Background.Start () (at Assets/Background.cs:27)