Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Transform child out of bounds

Discussion in 'Scripting' started by SFpreAlpha, May 15, 2019.

  1. SFpreAlpha

    SFpreAlpha

    Joined:
    Nov 22, 2016
    Posts:
    6
    Hi. I am having a problem after implementing a rarity system in my game.

    When I slay a monster It drops loot. When I try and loot it, I am given an error that says: Transform Child out of bounds. Then my game freezes. Looting was working perfectly fine until I implemented rarity UI around the edges of my items I pick up.


    Code (CSharp):
    1. {
    2.                             UILoot lootContents = gameObject.GetComponent<UILoot>();
    3.                             if (lootContents.panel.activeSelf)
    4.                             {
    5.                                 UILootSlot slot = lootContents.content.transform.GetChild(i).GetComponent<UILootSlot>();
    6.                                 raritySlot = slot.GetComponent<UCE_RaritySlot>();
    7.                                 raritySlot.rarityOutline.color = Color.clear;
    8.                             }
    9.                         }
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    That's because your "i" variable is either less than zero or more than lootContents.content.transform.childCount.