Array of NetworkViewID passing in a RPC

Hey guys,
I know that i can just send some types of variables in a RPC, and to pass an array of strings or numbers, i can easily create a string with some separator character and split then on the client, but my situation is different, i need to pass an array of NetworkViewIDs in a RPC. I know i can send networkViewIDs but they need to be seted in script, i need it dynamic, and i cant read it as string because it has some properties that cant be shown.

Can anyone help me with this?

Thanks.

1 Answer

1

NetworkViewID is a struct that contains internally 3 private ints. However the only way to access those values directly would be using Reflection but i wouldn’t recommend that!

The only two legit ways i can see is to:

  • send multiple RPCs each one with a different ViewID
  • use OnSerializeNetworkView to manually transfer the data you need.

The second method is probably a bit faster but it’s a bit complicated to achieve. I guess you want send the IDs to new players as initialization? As a one-time-events it doesn’t really matter if you send them seperated. If you really have a lot of IDs to sync you should even stretch the initialization over multiple frames to reduce network peaks using a coroutine.

yea, what i did it's send many separated RPCs, because they are just when a new player enter the match. Thanks