Search Unity

Why use Advanced CSharp Messenger instead of Delegate/Event or Action?

Discussion in 'Scripting' started by Ragee, Dec 30, 2020.

  1. Ragee

    Ragee

    Joined:
    Nov 24, 2012
    Posts:
    15
    When I first started learning about Unity the Advanced CSharp Messenger(http://wiki.unity3d.com/index.php/Advanced_CSharp_Messenger) was always recommend to use. But in all my recent learning its either been Delegate/Event or Action used.

    I have tried to wrap my head around what is actually best to use.

    I prefer using Action since its much cleaner but worried this hurt performance. There must be reason for the Advanced CSharp Messenger existing otherwise why would you go to the length of adding that to the project?

    The book "Unity in Action" made me even more confused as its states "...make use of a broadcast messanger system. Although Unity doesn't have feature built in...". How can this be true, C# comes with Delegate/Event or Action?
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
  3. dani-unity-dev

    dani-unity-dev

    Joined:
    Feb 22, 2015
    Posts:
    174
    The point there is decoupling. The receiver does not need to know who is raising the event.
     
  4. Ragee

    Ragee

    Joined:
    Nov 24, 2012
    Posts:
    15
    Started rewriting part of the code in my current project using CSharp Messenger and I must say that not needing to point specific broadcaster is awesome. Can't believe it took me this long to understand how useful it is.

    Thank you for the replies :)
     
  5. dani-unity-dev

    dani-unity-dev

    Joined:
    Feb 22, 2015
    Posts:
    174
    In my experience one downside is that the code becomes harder to read when you have enough messages being sent around.