Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
track event delegate registration, to spot unbalanced addition and removal...
//sometimes, when it's not your codebase and you have a lot of events flying round,
//it's useful to spot where an event may have been registered twice on the same component,
//or added and not removed (reference retained outside lifecylce of GameObject)
//this expansion of the event property may help...
//note: for whatever reason target may be null...
//pro tip: use the console to backtrack to the source of the registration
//
//idea adapted from juval Lowy: Programming .Net Components (O' Reilly)
private event EventHandler m_onClick;
public event EventHandler onClick
{
add
{
m_onClick += value;
Debug.LogFormat("adding delegate {0} to GO {1} now has {2} delegates", (value as Delegate).Target, GetInstanceID(), m_onClick.GetInvocationList().Length);
}
remove
{
Debug.LogFormat("removing delegate {0} to GO {1} now has {2} delegates", (value as Delegate).Target, GetInstanceID(), m_onClick.GetInvocationList().Length);
m_onClick -= value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.