0

I'm currently making a Unity Multiplayer game that relies on the synchronization of variables across the Server and the singular Client. I'm already able to use [SyncVar] to sync variables from the server with the client, but not the other way around. The thing is, I don't have a player prefab that spawns in the game. Am I still able to make Command and RPC calls? I tried this code below which didn't end up working when I played the game. Would Network messages work better for my situation?

bool officeBought = false;

void Update () {
    if (!isServer)
    {
        CmdSendBuildingBought(officeBought);
    }
}

[Command]
public void CmdSendBuildingBought(bool buildingBought)
{

    buildingBought = true;
}
  • Commands can only be sent from a Player object in your client to the according Player object on the server. Otherwise yes you will have to use Network messages. (But not sure .. maybe you still need some kind of player/client prefab?) Just for interest: why are you making a multiplayer game without any player objects? (You know that a player object could as well be a static invisible GameObject just for making Commands and Rpc work? This would probably ease things a lot?) – derHugo Nov 07 '18 at 06:02

1 Answers1

0

As derHugo says you need to instantiate at least one PlayerObject on the game BUT:

You didn't have to use it if you don't want it, but you need at least to instantiate one on the scene to assign the "Authority" to the object that you want to make de CMD/RPC calls.

More information about Unet Authority here: https://docs.unity3d.com/Manual/UNetAuthority.html

Also let me suggest another answer that I made on this particular question, as I think it will be your next step: Problem in authority shifting of non-player object

Lotan
  • 4,078
  • 1
  • 12
  • 30