1

I am working on such a simple thing as having a UI button that sends a command to print in a multiplayer (UNET) environment. Given what i have done so far i thought this would be easy but i am totally stucked and confused.

I have created a new project, to test, but I am still not able to get this to work. I am able to spawn and trigger the button's onClick i still get "Trying to send command for object without authority". I have the Canvas & button as a prefab and I have attached the script, below to the Canvas prefab and then the canvas to the button OnClick property.

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class NM_Script : NetworkBehaviour {

public void DoButton() {

    Cmd_Print ();
}

[Command]
void Cmd_Print() {
    print ("HIT");
}
}

After all the different testing i am at a point that i "probably" do not see the forrest because of the trees and I am getting quite frustrated. I know the solution is simple and obvious and that i should be able to solve it but....

I would really appreciate if someone could help me to solve this once for all.

Programmer
  • 121,791
  • 22
  • 236
  • 328
PeterK
  • 4,243
  • 4
  • 44
  • 74
  • Are you sure that you're properly connected ? There is something like CommandAttributes being initialized only when the networkserver has set all players to ready. – FLX May 12 '16 at 10:14

1 Answers1

0

From UNET documents,

For security, Commands can only be sent from YOUR player object.

Starting with Unity release 5.2 it is possible to send commands from non-player objects that have client authority. These objects must have been spawned with NetworkServer.SpawnWithClientAuthority or have authority set with NetworkIdentity.AssignClientAuthority. Commands sent from these object are run on the server instance of the object, not on the associated player object for the client.

Stef Geysels
  • 1,023
  • 11
  • 27
Arun
  • 3
  • 5