GetComponents Just wont work ... any idea?

	var nview : NetworkView[] = GetComponents(NetworkView) as NetworkView[];
	Debug.Log(nview.Length);
	for(var n : NetworkView in nview){
		n.enabled = false;
	}

always comes back null , ireally not sure why. I have been looking in the refernce articles, it claims always best ot use a type, and yet , exactly same and not working.

The only difference is now i have tried using “as NetworkView” … thats not in the docs, but trying exactly their way Unity complains about not being able to Cast it …

I Also though i remembered reading somewhere , that if you had multiple networkViews on an object, you could access them through an array , but i have not had any luck there either.

A simple yet subtle problem, GetComponents returns an array of Component objects, or Component[ ]. There is no conversion from “Component[ ]” to “NetworkView[ ]”, as the types are not covariant with eachother. While just “NetworkView” inherits from “Component” and you can cast from Component to NetworkView, there is no such relationship between their array types.

Basically what you have to do is to accept the Component[ ] result from GetComponents, and then create a new array of NetworkView[ ] with the same size, then loop over the Component[ ] array and cast each bject into a NetworkView and put it in the same slot in the NetworkView[ ] array.

Ohhh , cool , thanks man , that explains , and solves alot :stuck_out_tongue: Merci.

The documentations has the same error as I see, or its simply outdated.

An alternative to

[FONT=monospace]
[/FONT]GetComponents(NetworkView)[FONT=monospace]
[/FONT]

you can use

[FONT=monospace]
[/FONT]GetComponents.<NetworkView[FONT=monospace]>()
[/FONT]

which returns according to the reference an array of NetworkViews, exactly what you want, without the need to manually cast every entry.