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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[Solved] What are the possible CommandAttribute parameters?

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

  1. Valtaroth

    Valtaroth

    Joined:
    Jun 8, 2013
    Posts:
    8
    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;
    5.  
    6.    public MoveAction(int _X, int _Y)
    7.    {
    8.       X = _X;
    9.       Y = _Y;
    10.    }
    11.  
    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

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,560
    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: http://forum.unity3d.com/threads/command-object-references.334755/)
    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

    Valtaroth

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