#ServerRpc doesnt get exectuted when called from client

1 messages · Page 1 of 1 (latest)

lime kelp
#
//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?
#

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

obsidian lotus
#

A ServerRPC will only ever run on server/host.

lime kelp
#

Yes

#

"but not look to the server"

#

I specified I looked at the server instance

flint bloom
lime kelp
#

Its expected that the server doesnt end up running that function?

flint bloom
#

No - that's not how I interpreted what you said.

lime kelp
#

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

flint bloom
#

I didn't say you were. I simply misread what you said

#

is PlayerController a NetworkBehaviour?

lime kelp
#

Yes

obsidian lotus
#

Is the player not owned by the client?

lime kelp
#

The screenshot is the client, ownership is true and it looks to be spawned properly

obsidian lotus
#

Its just weird for the player client to be the owner but not the LocalPlayer

lime kelp
#

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

obsidian lotus
#

Do you have the player controller for other players disabled on the server/host?

lime kelp
#

what do you mean? I disable them when they arent owner so to not run code twice?

flint bloom
#

The script needs to be enabled on the server for it to receive an RPC

lime kelp
#

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

flint bloom
#

You might be able to disable the player input?

lime kelp
#

It also has other entrypoints with a few public methods as well as spawn disable and the like

#

Ill just error my way to finding where I missed a check xd