- Home /
Networking Destroy Player's RPC function uhm WHAT?
ok the Q may be seem trivial to you but I just started learning networking I don't understand aloot.
I was starting to trying to figure out how to give each player a specific class when he logs in and so and how to destroy that class he "owns" on server and stuff like that, ... but I've run in to the documentation witch turned my head around (like I understood gravity but now I don't any longer), ...
Been reading this 2 manuals:
-
using UnityEngine; using System.Collections;
public class Example : MonoBehaviour { void OnPlayerDisconnected(NetworkPlayer player) { Debug.Log("Clean up after player " + player); Network.RemoveRPCs(player); Network.DestroyPlayerObjects(player); } }
well I've figure out I'll probably need OnPlayerDisconnected since I was searching for:
[RPC]
void SomeFunction (NetworkMessageInfo Info){
}
so I would somehow figure out how to determen witch class to destroy, ...
BUT as far as I knew the:
client was sending RPC functions to server
server was verifying if server knows that exact RPC functions and executed them
but now I'm reading:
Network.RemoveRPCs(player);
so what does it do?:
connects back to client and deletes the functions I've wrote on client? kinda highly unlikely, ...
Deletes the RPC functions on the server to witch server has access since client has disconnected and deletes them so other clients cannot use them any longer?
OR even more strange thing to reverse the process and calculates the WHOLE thing how else would physics go if that player wouldn't do any RPC calls, ...
like the title says uhm WHAT?, ... it puts all the logic I understand on the head, ...
the second thing if there's a function call:
Network.DestroyPlayerObjects(player);
how do I tell that function what objects ARE the objects this particular client has? or will it delete everything this client has touched meaning half of my HDD with him, ...
I'm sorry this documentation totally confuses me and puts all my logic on the head, .. can some one turn it back on please, ... OR my head will start to hurt, ...
Answer by Jamora · Aug 23, 2013 at 10:12 PM
No one truly knows how Unity's networking works; I answered this question with how I think Unity determines object ownership and not everyone agreed with me...
Basically, I believe the server keeps track of all connected players, what objects they've created and what RPCs they've sent. (This is also the reason everyone sees the server as the owner of all network.instantiated objects, unless the player himself instantiated it.)
I would imagine that the server just keeps a data structure of all RPCs and Objects instantiated by everyone. Calling Network.RemoveRPCs(player);
just clears all buffered RPCs from that data structure so the server doesn't send them to any newly connected player. Conversely, calling Network.DestroyPlayerObjects(player);
just destroys the GameObjects that are Network.Instantiated by player on each client. So basically the server just does something similar to networkView.SendRPC("Destory",RPCMode.All,listOfObjects);
in that post you said:
Though you can set it up as a p2p (server) so how do you do that?
thanks, ...
this is pretty informative :)
before I was instantiating objects with RPC function like:
[RPC]
void something (int i){
if (i == 1){
Instantiate(SomeGameObject);
}
}
I still think this way is more efficient and was thinking how to keep track so new player does not connect to this same GO that I would verify with string username AND if disconnected I would delete the class he was using it but store the values.
and thanks this gives me a bit of a jump since I didn't know I could call network.instantiate object will dig more in those lines.
I said p2p, but I actually meant a sort of a hybrid. You can set a semi-p2p network by storing each player's NetworkPlayer on each client, so that each player knows every other player in the game. This can be achieved by the server sending an RPC to everyone to add a new player in OnPlayerConnected.
Once every player knows each other NetworkPlayer, they can use the version of RPC with the NetworkPlayer parameter to send data directly to that player.
This won't be true p2p in the sense that if the server disconnects, every client will be disconnected as well.
As for your question of keeping track of connections, it sounds like a topic for a new question. Do remember to put in more information on what you're trying to achieve, because currently I don't understand the question.
to send data directly to that player?
that's exactly what I was looking for I need that to lower bandwidth.
can you provide the code please.
what I want to achieve is only learning for now. basically when I write code I never know what my goal is but I build like what seems best at that point and I write forward.
and currently I'm trying to make tracking each client when it logs in and if connection breakes and get's back in that he can still play but if off connected for more than 5 $$anonymous$$ he's loged out. BUT that no other client cannot replace him when he's disconnected, ... maybe I could maybe I cant , ... I'll play with this tomorrow.
that's why it's fun program$$anonymous$$g for me and that's why I haven't stopped at first step towards big $$anonymous$$$$anonymous$$ORPG game or what ever it my be the result.
I'll be playing with this more tomorrow, yes that's way out of topic thanks for putting the logic back on and if tomorrow I'll reach another road block I'll ask a question.
You got that wrong. It's just a kind of p2p. All data will always go through the server, so that wouldn't lower the bandwidth at all. In the end it will always be a client - server - model. If a client has the networkplayer object of another client he can send an RPC to this client only, but it will still go through the server since that's the only connection a client has.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
UNET Health isn't syncing 1 Answer
Making a list of distinct IPs broadcasting UDP 0 Answers
C# How to have a gun select 1 Answer