- Home /
How to use Network.Instantiate Groups
I'm trying to use groups in my Network.Instantiate calls to only create objects for some of the connected players. The unity documentation as I understand it states that's the purpose of the groups:
"Communication groups can be used to select the clients that will receive particular messages..."
What I think I'm missing is an example of how to set the network group of a player (the server can be a player too).
I've tried used Network.SetReceivingEnabled
and Network.SetSendingEnabled
in as many ways I can think of with no effect.
Ultimately I want to be able to Network.Instantiate
on group 0 for all players, group 1 for a subset of players (team 1), and group 2 for another subset of players (team 2).
Answer by fifthknotch · Mar 07, 2014 at 04:21 AM
You specify what group number inside as one of the parameters of Network.Instantiate.
static function Instantiate(prefab: Object, position: Vector3, rotation: Quaternion, group: int): Object;
Check out: http://docs.unity3d.com/Documentation/ScriptReference/Network.Instantiate.html for more info.
I understand that, but how do I set the group on a connected player? Say I call Network.Instantiate for group 2, how do I set which clients are in group 2?
When you Instantiate the clients, are they instantiated to group 2?
When clients connect to the host I'm not seeing a place where I can set which group they belong to.
So, I have a network game I made, and in my script that connects my client to the server, it loads a lobby. When my game starts, all clients Instantiate a player and that is where the group number would be assigned depending on what $$anonymous$$m there are on.
Interesting. I have the same setup where each player will instantiate a prefab when the game starts. So you're saying when that initial Network.Instantiate call is made for each player's character the group number in that Network.Instantiate call is setting the network group for that player? Could you post the line of code that assigns the group number? Seems very unintuitive but I'll give it a try tomorrow.