- Home /
Duplicate Question
Why is the child transform giving me errors?
UnityException: Transform child out of bounds GUI_Buttons.Start () (at Assets/Codes/GUI_Buttons.js:12)
that is mah error
pragma strict
/icon variables are the ones that selected are is. Don't judge my groamar. var useAllVariables : boolean; var Icon: Material; var Icon2: Material; var Text: Material; var backImage: Material; var normalIcon: Material[];
function Start () { normalIcon[0] = renderer.material; normalIcon[1] = transform.GetChild(0).renderer.material; if(!useAllVariables) return; normalIcon[2] = transform.GetChild(1).renderer.material; normalIcon[3] = transform.GetChild(2).renderer.material; }
function OnMouseEnter () { renderer.material = backImage; transform.GetChild(0).renderer.material = Icon; if(!useAllVariables) return; transform.GetChild(1).renderer.material = Icon2; transform.GetChild(2).renderer.material = Text; }
function OnMouseExit () { renderer.material = normalIcon[0]; transform.GetChild(0).renderer.material = normalIcon[1]; if(!useAllVariables) return; transform.GetChild(1).renderer.material = normalIcon[2]; transform.GetChild(2).renderer.material = normalIcon[3]; }
Please format your post properly. Why will anyone bother to help (i.e. spend their time) if you do not invest time your into posting a properly formatted question?
@Fattie, there is no need to punish people on the first time. Educate ins$$anonymous$$d. The goal is to build stronger community - not to be formatting police ;)
Answer by Sajidfarooq · Aug 15, 2013 at 12:10 PM
As already answered here: http://answers.unity3d.com/questions/261136/child-transform-out-of-bounds.html
You are trying to access a child (transform.GetChild(0) ) of a Transform without making sure that it actually does have children in the first place...
Answer by TheKusabi · Aug 15, 2013 at 12:40 PM
Formatted for you. Next time, I suggest you do this yourself or people will not give you the time of day.
pragma strict // icon variables are the ones that selected are is. // Don't judge my groamar. var useAllVariables : boolean; var Icon: Material; var Icon2: Material; var Text: Material; var backImage: Material; var normalIcon: Material[];
function Start () { normalIcon[0] = renderer.material; normalIcon[1] = transform.GetChild(0).renderer.material; if(!useAllVariables) return; normalIcon[2] = transform.GetChild(1).renderer.material;
normalIcon[3] = transform.GetChild(2).renderer.material;
}
function OnMouseEnter () { renderer.material = backImage; transform.GetChild(0).renderer.material = Icon; if(!useAllVariables) return; transform.GetChild(1).renderer.material = Icon2;
transform.GetChild(2).renderer.material = Text;
}
function OnMouseExit () { renderer.material = normalIcon[0]; transform.GetChild(0).renderer.material = normalIcon[1]; if(!useAllVariables) return; transform.GetChild(1).renderer.material = normalIcon[2];
transform.GetChild(2).renderer.material = normalIcon[3];
}
Error Message: "Transform child out of bounds GUI_Buttons.Start () (at Assets/Codes/GUI_Buttons.js:12)"
As for an answer, best guess is that the GameObject does't have three children and you are trying to access transform.GetChild(2) which is the third child. Change that number in all of the functions.
Good luck!
$$anonymous$$udos for taking the time out to do what the OP should have done in the first place. Up-voted.