Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OnMouseDown

Discussion in 'Multiplayer' started by TsuRIL, Mar 23, 2017.

  1. TsuRIL

    TsuRIL

    Joined:
    Mar 17, 2017
    Posts:
    3
    I'm making a game and i use "OnMouseDown" in one of the scripts but for some reason if a client tries to press the object the console writes:
    Trying to send command for object without authority.
    UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String)
    Deck:CallCmdSpawn()
    Deck:OnMouseDown() (at Assets/Deck.cs:31)
    UnityEngine.SendMouseEvents: DoSendMouseEvents(Int32)

    can some one tell me plz how can i give all players authority?
     
  2. l3fty

    l3fty

    Joined:
    Mar 23, 2013
    Posts:
    86
    So for a player to call a [Command] on an object, it requires authority. The player is given authority of their player object (If using the HLAPI), and the server can give them authority on other objects. However I'm reasonably sure that only one player can have authority of an object at a time (Someone can correct me here if that's wrong).

    If you have an object that you want multiple players to be allowed interact with, you have a couple of options that I can think of:

    1) Use a command on your player object which then talks to the 'central' object on the server. When you call a [Command] from a client, that method executes on the server, where it can then talk to any server object however you like. Your server object can then broadcast any state changes to everyone if desired.

    2) Use messages - The client can send messages to the server, which your central object can listen for and react to however you like, circumventing the authority system. Both clients and servers can register message handlers for directed communication. https://docs.unity3d.com/Manual/UNetMessages.html

    Hope this helps!
     
    TsuRIL likes this.
  3. TsuRIL

    TsuRIL

    Joined:
    Mar 17, 2017
    Posts:
    3
    well I thought it worked but now it doesn't let me send Commands again (no authority) and the script is on the player now