Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Cmd vs if (!isServer)

Discussion in 'Connected Games' started by hottabych, Jul 3, 2018.

  1. hottabych

    hottabych

    Joined:
    Apr 18, 2015
    Posts:
    61
    What's a difference if I use Command to run code on the server, or if I simply run the method and use an `if (!isServer) return` construction or [Server] attribute? Result should be the same: it tries to run the code on all copies of a gameobject and does it on server only.
    There are both ways used in Simple Multiplayer tutorial in the Learn section. Cmd for bullet spawning and isServer check for TakeDamage.
     
  2. Ellernate

    Ellernate

    Joined:
    Aug 25, 2017
    Posts:
    77
    Command is used by a non-authority to directly send something to whoever has authority over the object (usually server). It's used in bullet spawning because that is the most logical way to communicate the intentions of the client. I'm curious to know how you do bullet spawning without using command or messages
     
  3. hottabych

    hottabych

    Joined:
    Apr 18, 2015
    Posts:
    61
    Well, why TakeDamage does not use Command in the tutorial? It's a logical way too, to send Cmd to server and ask it to change the player's health.
     
  4. hottabych

    hottabych

    Joined:
    Apr 18, 2015
    Posts:
    61
    I think you understand something wrong. Only Player or object with Client Authority can send commands (always from client to server).
     
  5. Ellernate

    Ellernate

    Joined:
    Aug 25, 2017
    Posts:
    77
    Ah, you're correct. I follow a strict client-server model so I sometimes overlook the local player authority stuff. I meant authority as in the server