Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Using [Command] attribute on non-networkgame

Discussion in 'Multiplayer' started by greatergoodguy, Aug 4, 2017.

  1. greatergoodguy

    greatergoodguy

    Joined:
    Jan 10, 2013
    Posts:
    7
    I'm working on a multiplayer game, and I've started on creating a single player mode. Is there a way to make the Command attribute behave as if the device itself is the server? Currently when I use a function with the Command attribute, I get the error
    "Command function CmdShowSpeech called on server"
     
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    You are calling the Command from the server instance.
     
  3. greatergoodguy

    greatergoodguy

    Joined:
    Jan 10, 2013
    Posts:
    7
    Hmmm I see. So if I'm doing a single player mode, it seems I won't be able to use methods that have the Command or ClientRpc attribute. If that is the case, what strategies do I have of architecting my code so that I can easily support local and multiplayer modes.
     
  4. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Yes you can. Just don't invoke the Commands from the server instance. Even if you are the host.