piece of code thats no longer working

This code

for (var child : GameObject in gameObject as GameObject[]) 

Returns the error when I hit play:

NullReferenceException: Object reference not set to an instance of an object

I think this started since Unity 3.5 since it worked before or I can not see what I may have done wrong here.

This is the whole script, I use it to control a bunch of seperate push scripts that are child objects for a conveyor belt.

	for (var child : GameObject in gameObject as GameObject[]) 
{
	var rPushScript : push_fixeddirection = child.GetComponent(push_fixeddirection);
	pushArray.Add(rPushScript);
	rPushScript.DisablePush();
	rPushScript.pushStrength = pushStrength;
}

edit this works but with a warning:

for (var child : Transform in transform) 

WARNING: Implicit downcast from 'Object' to 'UnityEngine.Transform'.

Your code doesn’t make much sense :wink:

.gameObject references the gameObject this script is attached to. It’s one gameobject. The as-cast will fail since a GameObject can’t ve casted into a GameObject array. The as-cast will return null if the cast fails without any warning.

A gameobject has no information about it’s child objects. All gameobject just live side by side in the scene. It’s the Transform component that build up a hierarchy between them.

The Transform component is also enumerable (it implements the IEnumerable interface).

for (var child : Transform in transform) 
{
    var rPushScript : push_fixeddirection = child.GetComponent(push_fixeddirection);
    pushArray.Add(rPushScript);
    rPushScript.DisablePush();
    rPushScript.pushStrength = pushStrength;
}

As a sidenote: Class names should start with a capital letter and usually you should use the upper CamelCase:

Push_FixedDirection