Search Unity

SendMessage vs StartCoroutine

Discussion in 'Scripting' started by madcalf, May 4, 2006.

  1. madcalf

    madcalf

    Joined:
    Jan 12, 2006
    Posts:
    56
    Is there any disadvantage to using SendMessage instead of StartCoroutine to call a function on another object? I like the idea of just having to reference the object:
    Code (csharp):
    1.  object.SendMessage("SomeFunction", param)
    rather than having to reference the script component of the object:

    Code (csharp):
    1. object.GetComponent(ScriptName).StartCoroutine("SomeFunction", param)
    But i want to be aware of any pitfalls of using SendMessage this way. Will coroutines will still work? Performance issues? Any other reasons I shouldn't do it?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    It depends on the situaton but usually the performance overhead is not noticable at all. Coroutines will still work with this.
     
  3. madcalf

    madcalf

    Joined:
    Jan 12, 2006
    Posts:
    56