Networking modify scene object

I have a little problem with my networking-test project. I have a simple scene bbject with a script attached and I want to allow the players to change a variable on the script (basically it is an interactable object, but only a single player should be able to interact with it at any given time). I thought this would be very simple, and maybe it is and I am just too stupid, but whatever I try, I can’t get it to work.

Things I tried:

  • added SyncVar attribute (with and without hook) (Host can change the variable and distribute it to remote clients, not vice versa. Remote Clients only lock themselves out)
  • added Command and RPC functions to the Object (doesn’t work because Object doesn’t belong to the player, so it cannot send commands)
  • added Command and RPC functions to a script on the player (I can’t pass the objects script to a Command, so I can’t edit this script’s variable in the Command)

None of these worked.

I am sure I am overlooking something very simple…

Fo anyone finding this question:

The solution was to identify the Scene Objects by their NetworkID.

I added a command to the player object that passes the NetworkID to the server and then calls a function on the found object.

[Command]
void CmdUse(NetworkInstanceId playerID, NetworkInstanceId objectID) {
    IUseable useable = NetworkServer.FindLocalObject(objectID).GetComponent<IUseable> ();
    if (useable != null) {
        useable.use (playerID);
    }
}