Referencing children of an instantiated object.

var Possibility1:GameObject;
var Possibility2:GameObject;
var Possibility3:GameObject;
var Possibility4:GameObject;
var Possibility5:GameObject;
var Choice : GameObject;
var AppearDist:int = 50;
var x:int;
var Player : Transform;
var Real_Object : GameObject;
var a : boolean = true;

function Start ()
Player = GameObject.FindWithTag("Player").transform;

function Update () 

if(a == true)
x = Random.Range(1.0, 5.0);
{Choice = Possibility1;}
{Choice = Possibility2;}
{Choice = Possibility3;}
{Choice = Possibility4;}
{Choice = Possibility5;}
Real_Object = Instantiate(Choice, transform.position, Quaternion.identity);

var dist = Vector3.Distance(Player.position, transform.position);

{ = false;
{ = true;


This script is supposed to create one of five objects at the place of an object it is attached to, and then calculate the distance between itself and the player. If the distance is big enough - disable the instantiated object. And then enable it again, when player gets close.

Problem is, it deactivates only the parent object, but not its children. I used the

for (var child : Transform in transform) 
    child.renderer.enabled = false;
	renderer.enabled = false;

for previous version of a script, attached to the instantiated object itself (back then I just made it invisible). Is it possible to reference the children of the instantiated object in this case?

Problem is, I can not search by Tag or something like that, because there is a whole grid of these with a random width, length and hight, so referencing should be local.

You should use GameObject.SetActiveRecursively.

Also deactivating a GameObject and disabling its renderer is not the same.