#Ahh. I don't understand why that is the
1 messages ยท Page 1 of 1 (latest)
You can have your exact setup with 0 player objects.
Where the Host is a client and hosting the server + another client connects to the server.
That means we have the Host as connection 0 and the client as connection 1.
Let's say we had 1 object in the scene, GameManager
There will be an instance of the GameManager object on the Host's screen, and one on the Client's screen
Yes
If we call an RPC marked SendTo.NotServer from the Host's GameManager object, it will be sent to the Client's GameManager object
I see you're using PlayerNetwork and putting it on each player object, which I think is causing your confusion
This is what I thought I was achieving :/
You're calling an RPC marked SendTo.NotServer on the Host's Player Object, and expecting it to be received on the Client's Player Object.
It will be received on the Client's version of the Host Player Object.
Which is why I would put this logic on an object/script called something like ConnectionManager
and use the ulong from NetworkManager.Singleton.OnClientConnectedCallback
and pass it through your RPC
to tell clients who just connected using the ulong ID.
[Rpc(SendTo.NotServer)]
void UpdatePlayerCountRPC(int playerCount, ulong playerConnectedID)
something like that
I'm aware of NetworkManager.Singleton.ConnectedClientsIds exists, I just wanted to use some data and pass it around ๐
Thanks for the help
This is only accessible by the server anyway, so you're correct in your approach
So is it possible to send data to clients Local Players from the server, in the way I am intending?
Yep!
Hmm is it via RPC with ulong ID by any chance ๐
Sending an RPC to a specific connection can be done with SendTo.SpecifiedInParams
You can also do this when working on Player Objects:
[Rpc(SendTo.NotServer)]
private void LocalPlayerObjectRPC()
{
if (!IsLocalPlayer) return;
// Tell the local player to run some code on their player object
}
Technically a waste of bandwidth, but ๐คทโโ๏ธ
Not the biggest deal in the world.
There are RPCTargets you can use as well
Any process can communicate with any other process by sending a remote procedure call (RPC). As of Netcode for GameObjects version 1.8.0, the Rpc attribute encompasses server to client RPCs, client to server RPCs, and client to client RPCs. The Rpc attribute is session-mode agnostic and can be used in both client-server and distributed authority...
Also allows you to run code for other clients before the return statement