Animation[] doesn't work when using GetComponentsInChildren?

I’m trying to make function that controls all the animations in children of some gameObject.

So I used the following code, it gave me this error:

var RudolfAnimations: Animation[];
var RudolfParticles: ParticleEmitter[];

function Update () {
}

function Start()
{
	RudolfParticles = gameObject.GetComponentsInChildren(ParticleEmitter);
	RudolfAnimations = gameObject.GetComponentsInChildren(Animation);
	
}

Actually, I can make this code work using:

var RudolfAnimations;
var RudolfParticles;

without setting the type of those variables.

But I’ve heard from somewhere that I should set the type of all variables when developing for iPhone. This project is for iPhone, so could anyone tell me how to make this work without using the solution above?

Thanks in advance :slight_smile:

Try this,

Code:

var RudolfAnimations: Animation[ ];
var RudolfParticles: ParticleEmitter[ ];

function Start()
{
RudolfParticles = gameObject.GetComponentsInChildren.();
RudolfAnimations = gameObject.GetComponentsInChildren.();
}

Thats a weird syntax but it works, thanks

If I recall correctly GetComponentsInChildren returns Component[ ]. This is why it works without specifying the type. if you try and do Animation = Component; unity won’t love you very much. The syntax above declares the return type so that also solves the problem.

I actually read this thread because I have the weirdest problem you can imagine. I have (amongst others) an animation called “running” on a character. Doesn’t matter if I rename it to run, _run or Run it simply won’t play. I print a list of animations during runtime and it lists “run” as one of the animations it finds. if I then go Animation[“running”] I get a runtime error… Hell, even if I extract the name of the animation at that index and then pass that variable as the name of the animation to play, it tells me that animation does not exist. Let me just repeat that: I extract the name from the AnimationState and use the name I got FROM the animation to tell it to run the animation and it tells me the animation was not found.

All my other animations I tested one by one using the exact same code and all work… except for that one, no matter what I call it. So I gave up on it and decided to play it as a loop using animation step and it works just fine… I just can’t imagine why all my animations run perfectly except for this one…