I am new at Unity, where is my fault?(It says UnityException: Transform child out of bounds GameManager.Update () (at Assets/Scripts/GameManager.cs:29)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour {
	private Transform randomSet;
	public Transform aktifSetler, pasifSetler;	
	// Use this for initialization
	void Start () {
		StartCoroutine(CheckForVisibility());
			
	}
		
	// Update is called once per frame
	void Update () {
		
	}

	void Recycle()
	{
		randomSet = pasifSetler.GetChild(Random.Range(0, pasifSetler.childCount));
		randomSet.parent = aktifSetler;
		randomSet.localPosition = aktifSetler.GetChild (aktifSetler.childCount - 2).localPosition + new Vector3 (0, 0, 0);
	
		randomSet = aktifSetler.GetChild (0);
		randomSet.parent = pasifSetler;
		randomSet.localPosition = pasifSetler.GetChild (0).localPosition;
	}
	IEnumerator CheckForVisibility()
	{
		while(true)
		{
			yield return new WaitForEndOfFrame(); 

			if (aktifSetler.GetChild (0).GetChild (1).GetComponent<SpriteRenderer>().isVisible == false)

		{
			Recycle ();	

}	
	}
}
}

yes this is exacly what i need ^^. and i want your help if you are the time^^

1 Answer

1

This error means that you are attempting to access a child index that simply does not exist, think of the children that you have parented to an object as an array, GetChild is indexing into that array, If you are looking at childen of those children then they are there own arrays, and thus have their own indexing.

For example, assume I had the following hierarchy.
Parent
----Child A
----ChildB
--------ChildB_A
--------ChildB_B

Parent.GetChild(0) and Parent.,GetChild(1) would return ChildA and ChildB respectively. If i was accessing the inner children of B then I would need Parent.GetChild(1).GetChild(0) and Parent.GetChild(1).GetChild(1).

Look at the line where your error is being thrown from and then take a careful look at your hierarchy to ensure that there is a child for it to find, You should find that either you’re calling a GetChild on an object with no children, or your GetChild(1) is being done on an object with only one child.

yeah sure ; send me a massage to my gmail ill help u cause there are lots of steps to talk about : savajjad@gmail.com