[problem] Trying to pass an array to method (C#)

Hi there,

I’m getting an errors while trying to pass an array to a method.

object [] array1 = new object [16];

for(int a=0;a<16;a++){

    array1[a] = new object();

}

getArray(array1);

void getArray(object [] array2){

    //do something with the array

}

the error says the method expects 1 argument but recieves 16, which is wierd to me cause it should recieve the array and not the objects seperatly or so I assume.

any help? :slight_smile:

I just read that an array isnt a valid argument of an RPC, hmm too bad, gnna pass em 1 by one…

Pass a pointer to the array?

will that work? Im actually gonna send it over the network… is a pointer enough?

im pretty sure its Object and not object. (with a capital o)

thats not the problem, its jsut a demostration code, the syntax is fine

Here’s the original code if it helps

Player_Info [] players = new Player_Info[16];

void Start(){
		
	if(Network.isServer){
		
		createArray();	
	}
		
}
	
void createArray(){
		
	for(int a=0;a<16;a++){
			
		players[a] = new Player_Info();
	
        }
}

void someFunc(){

    networkView.RPC("updateArray", RPCMode.All, players);

}


[RPC]
	void updateArray(Player_Info [] playerArray){
		
		print("sendArr");
		Camera.main.SendMessage("getUpdatedArray", playerArray);		
		
	}

Tookin straight from the wiki :slight_smile:

Yeah, so it seems, :smile: I solved it already by passing the vars one by one when needed, thnx for replying guys.