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. Dismiss Notice

Is Delegate a good way to dispatch event ?

Discussion in 'Scripting' started by squirrel fury, Aug 15, 2014.

  1. squirrel fury

    squirrel fury

    Joined:
    Aug 15, 2014
    Posts:
    4
    Hi guys,

    I'm wondering if it is a good idea to use Delegate to notify that a variable value has just changed ? Would it be a good idea even if the variable could change very often like in the Update function of my game Model class ?

    Thank you
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    That's what delegates were made for, just like events.
     
  3. squirrel fury

    squirrel fury

    Joined:
    Aug 15, 2014
    Posts:
    4
    Ok, then I will go for that solution ! I'm just starting C# so I wasn't sure what is the solution to dispatch an event, needed to ask ;-)

    Thank you
     
  4. Pati-Co

    Pati-Co

    Joined:
    Jan 9, 2014
    Posts:
    56
    Almost every event based on combined delegats ;)
     
  5. Sharp-Development

    Sharp-Development

    Joined:
    Nov 14, 2013
    Posts:
    353
    Infact events are nothing more than syntax sugar around delegates, scoped with add/remove properties similar to getters/setters.