Typecast a Transform During a for Loop

Pretty sure there’s an easy answer to this.

I’m trying to figure out how to typecast the following but Unity keeps telling me I can’t convert and Object to a Transform. It is of course automatically downcasting but I want to explicitly set it.

Here’s my original source code:

for(var _child : Component in transform ) {
	if(_child.particleEmitter)
		_child.particleEmitter.emit = true;
}

And here are all the variations I’ve tried but with no success

for(var _child : Transform in transform) {
	if(_child.particleEmitter)
		_child.particleEmitter.emit = true;
}

for(var _child : Transform in transform as Transform) {
	if(_child.particleEmitter)
		_child.particleEmitter.emit = true;
}

for(var _child : Component in transform as Component) {
	if(_child.particleEmitter)
		_child.particleEmitter.emit = true;
}

for(var _child : Component in transform) {
	if(_child.particleEmitter)
		_child.particleEmitter.emit = true;
}

var _tempTransform : Transform = transform as Transform;
for(var _child : Transform in _tempTransform) {
	if(_child.particleEmitter)
		_child.particleEmitter.emit = true;
}

var _tempTransform : Component = transform as Component;
for(var _child : Component in _tempTransform) {
	if(_child.particleEmitter)
		_child.particleEmitter.emit = true;
}

var _tempTransform : Transform = GetComponent(typeof(Transform)) as Transform;
for(var _child : Transform in _tempTransform) {
	if(_child.particleEmitter)
		_child.particleEmitter.emit = true;
}

This alternative (similar to the one used in the docs) should work fine:

for(var _child : Transform in transform) {
    if(_child.particleEmitter)
       _child.particleEmitter.emit = true;
}

From the error message I suspect that you have an untyped variable called transform anywhere in your script, and it’s hiding the property transform. If you can’t find this mysterious variable, try to change the code to this:

for(var _child : Transform in gameObject.transform) {
    if(_child.particleEmitter)
       _child.particleEmitter.emit = true;
}

for (t in transform) {
var child = t as Transform;
if (child.particleEmitter)
child.particleEmitter.emit = true;
}