- Home /
UNET Client Cant Send Server Commands, Host Can.
So as the title suggests, I'm having a problem where commands being sent by the client are not triggered.
The basic functionality I'm trying to get working is that when an enemy is in front of the player and I click, that player will be momentarily stunned. Works fine if I'm host, and both sides perfectly register.
If I'm playing as client, I get to the point where the command "should" be sent, but I notice I get a warning that says "Trying to send command for non-local player". As well, nothing happens on either end. Obviously I must be doing something wrong client side, but have no idea what other way to go about this.
The "problem" code.
if (Input.GetButtonDown("Fire1")) {
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit = new RaycastHit();
Physics.Raycast(ray, out hit, 20f);
if (hit.transform != null) {
if (hit.rigidbody != null) {
PlayerController controller = hit.rigidbody.GetComponent<PlayerController>();
if (controller != null) {
if (!controller.stunned) {
// Send the stun command to the server
controller.CmdStun();
}
}
}
}
}
The method calls
[Command]
public void CmdStun() {
// Report that the stun was sent
UnityEngine.Debug.Log("Stun Sent");
RpcStun();
}
[ClientRpc]
public void RpcStun() {
// Activate the stun timer.
stunTimer.Start();
// Track the players original color.
normalColor = manager.color;
// Make the players bot look like its shut down.
manager.InitiateColorChange(Color.black);
// Other code will check against this before trying to send another stun command.
stunned = true;
}
Heres the two scripts in their entirety.
Player configuration in unity:
https://gyazo.com/400c5b3a95c1a58f9b6e930b0c3c853b
Does your player prefab have the Local Player Authority box checked in the Network Identity? It might be helpful to post some screenshots of the Inspector because I've found problems like this can arise due to those settings even when the script itself is correct.
Updated the question, Everything is properly configured as well.
Looking at everything so far, my first guess would be to try setting Local Player Authority to true on the $$anonymous$$overioCameraRig's Network Identity, since it is the one calling the command. You might also try making ObjectInteractor a Network Behaviour, but I'm not so sure that it's necessary.
I'm also wondering if you might want to put in an isLocalPlayer check into CmdStun() because there's a possibility that it's being called on both the host and the client simultaneously, which could lead to that error you were seeing. Again, I'm not too sure about this without trying it myself.
Answer by LeopardX · Dec 02, 2015 at 06:43 PM
Make sure your calling the command in a class on the player object, you cant do it any other way unless you spawn an object with authority.
Your answer
Follow this Question
Related Questions
UNet | I'm having trouble assigning authority to game objects 0 Answers
Unity networking tutorial? 6 Answers
Qos type ReliableFragmented channel, won't fragment our stream 2 Answers
Only one player for the host but two for the client, 0 Answers
[UNET] Connection between Client and Server dies without message 0 Answers