In Unet,
1. Only the SERVER can spawn any object - end of story
In Unet, servers spawn objects and that's it. End of story.
2. You HAVE TO HAVE "player" objects. Every client absolutely MUST have a "player" object.
It's totally normal that the "player" object is not actually a tank or biped - but is simply an empty game object. (Sometimes called an "abstract player object").
Every client MUST have a "player object" - often just an empty game object
3. Regarding spawning objects which have client authority - see point 1.
It's very easy to spawn objects with client authority. Just go to the doco page Manual/UNetSpawning.html and scroll down to
Code (CSharp):
NetworkServer.SpawnWithClientAuthority(treeGo, conn);
It is explained there (really that's all there is to it).
4. Say some specific player, X, will have the authority over the object. Of course, you can't spawn the object until X has joined!
In the line of code just above, people often ask how the hell do you know which "conn" NetworkConnection
to use?
Of course, it is meaningless until X has actually joined the game! See point 2!
So you might do things like this...
Example 1 - only one specific client is your "mothership". Of course, the server must, obviously, know the NetworkConnection
to that client. You'll have it saved in a variable networkConnectionToMothership
. Thus, in this example, you have the "conn" to use.
or
Example 2 - a client (say, client JohnSmith) wants to spawn an object which JohnSmith will have authority over. Quite simply, the client (JohnSmith) asks the server to spawn the object. "Asks the server" simply means send a Command
.
Inside any "Command" (ie, running on the server) you literally have the property connectionToClient
which gives you the "conn" needed!
So that's the deal.
For this specific question, in your code you are calling NetworkServer.spawn
.
You should be calling
NetworkServer.SpawnWithClientAuthority(treeGo, conn);
(Search for that on this doco page: Manual/UNetSpawning.html )
and I have explained above in example (2) how you would know what "conn" to use.