Search Unity

SendMessage with more than one arg?

Discussion in 'Scripting' started by wyliam, Apr 6, 2009.

  1. wyliam

    wyliam

    Joined:
    Mar 28, 2009
    Posts:
    61
    Does Unity restrict you to only one argument to pass in SendMessage?

    For example I have:

    Code (csharp):
    1. SendMessage("MyMethod", int, int, float)
    2.  
    Is that not legal?
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you can send as much as you want. But you must put all in the same object.

    the easiest to handle is likely a Hashtable
     
  3. wyliam

    wyliam

    Joined:
    Mar 28, 2009
    Posts:
    61
    I'm not sure I'm following. Would you mind providing a quick example? :)

    Currently I've got a single method that accepts 3 arguments (int, string, string).

    This method exists in a different script on the same object.
     
  4. AmazingRuss

    AmazingRuss

    Joined:
    May 25, 2008
    Posts:
    933
    I think he means, create a class that contains all your parameters, and pass an instance of that class as your parameter.
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Correct

    SendMessage accepts a single object to be sent.
    What type of object that is, is up to you.
    Hashtables are nice because they allow you to store anything in them you want with usefull ways to get the stuff back out again.
    The alternative, in some cases, are different data stored in a string.
     
  6. wyliam

    wyliam

    Joined:
    Mar 28, 2009
    Posts:
    61
    I see. It's unfortunate I can't explicitly use more than one argument.

    perhaps a wish list item...