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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Unity Multiplayer [Solved] What are the possible CommandAttribute parameters?

Discussion in 'Multiplayer' started by Valtaroth, Jun 22, 2015.

  1. Valtaroth


    Jun 8, 2013
    Hi guys,

    calling methods with the [Command] attribute works fine for me if they have no parameters or simple ones like strings and integers. Now, to make things easier I wanted to use a custom class as parameter looking like the following example:
    Code (csharp):
    1. public class MoveAction
    2. {
    3.    int X;
    4.    int Y;
    6.    public MoveAction(int _X, int _Y)
    7.    {
    8.       X = _X;
    9.       Y = _Y;
    10.    }
    12.    public void Execute()
    13.    {
    14.        // Movement code
    15.    }
    16. }
    Whenever I use it though, the parameter the server receives is null. I tried deriving it from ISerializable and implemented the necessary methods (another constructor and GetObjectData(..)) but that didn't change anything.

    Can methods with the [Command] attribute only receive the most basic data types as parameters or am I missing something here?
  2. liortal


    Oct 17, 2012
    I think this was mentioned somewhere on the forums here lately by @seanr
    1. You can pass in any primitive type / string, GameObject that has a NetworkIdentity at its root, or a NetworkIdentity instance (see this post:
    2. In next versions they will add better enforcing via errors / warnings so you know you're doing something wrong.
    Last edited: Jun 22, 2015
  3. Valtaroth


    Jun 8, 2013
    I see, what a shame. Thank you!