//PlayerController.cs
private void OnStartLook(InputAction.CallbackContext context)
{
Vector2 value = context.ReadValue<Vector2>();
print(value);
LookServerRPC(value);
}
...
float xRotation = 0f;
[ServerRpc(RequireOwnership = true)]
private void LookServerRPC(Vector2 look)
{
print(look);
transform.Rotate(Vector3.up, look.x);
xRotation -= look.y;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
playerCamera.transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
}```
on the Host it works fine, but when I call it from the client It prints only value to the client, but not look to the server (Using Multiplayer Play Mode).
The screenshot is the client, ownership is true and it looks to be spawned properly
Why doesnt it call the RPC properly?
#ServerRpc doesnt get exectuted when called from client
1 messages · Page 1 of 1 (latest)
Idk if its important for this. The image on the first message is PlayerCharacter, while Player is just what the networkmanager instantiates as the player object. Player also is an NO that is also Owned
A ServerRPC will only ever run on server/host.
That would be the expected behaviour. A client calls a ServerRpc to send a networking message to the server to tell the server to run that function.
Its expected that the server doesnt end up running that function?
No - that's not how I interpreted what you said.
I said that the server rpc which I try to print doesnt print to the server
Im not stupid Im not trying to see the print in the ServerRpc on the client
Thats why I even specified that I looked on the server
I didn't say you were. I simply misread what you said
is PlayerController a NetworkBehaviour?
Yes
Is the player not owned by the client?
The screenshot is the client, ownership is true and it looks to be spawned properly
Its just weird for the player client to be the owner but not the LocalPlayer
Because LocalPlayer is on Player not PlayerCharacter, but PlayerCharacter is the one I wanna move
I dont move the LocalPlayer because the thin g that moves can die (thus despawn)
I dont think despawning the localplayer is all too smart
Do you have the player controller for other players disabled on the server/host?
what do you mean? I disable them when they arent owner so to not run code twice?
The script needs to be enabled on the server for it to receive an RPC
oh, I thought I'd rather disable it instead of checking on every method, as this reduces points of error to one instead of every entry point but then I guess I cant do that
You might be able to disable the player input?