So I'm digging around to see if I can pinpoint it further. I've figured this out:
1 - It probably has something to do with Reflection and how the callback cache is implemented
2 - @Nicki - when you replaced the lambda function to just do the Debug.Log(), it actually changes the Callback object; i.e., there's no "target" if gameObject is not referenced, hence everything is happy, so that's a red herring. Not a timing issue.
3 - This issue is related to the anonymous function - if I change (in BaseDialog.cs)
EventDelegate.Add (mainTween.onFinished, () => {
gameObject.SetActive(false);
}, true);
To
EventDelegate.Add (mainTween.onFinished, DoStuff, true);
while adding:
protected void DoStuff(){
gameObject.SetActive(false);
}
everything is happy.
I've diagnosed the issue to be the following:
When the anonymous method is added to the EventDelegate list, the method name is "saved/cached" in the EventDelegate list as <Hide>m__2. However, when EventDelegate goes through its list of callbacks to execute, when it pulls this particular function from the list, it tries to retrieve the method (via GetMethod in EventDelegate.cs:355) with the method name <Hide>m__2, which seems to be only valid for BaseDialog, but not NewDialog, so it fails if the triggering class is from the inherited class. Hence, if the anonymous function was replaced with a named function, GetMethod seems to be able to find the method from the inherited class with no problems (provided the proper accessibility modifiers are in place).
I'm not sure how to fix this yet, I'm not extremely familiar with Reflection - maybe ArenMook has an idea. In the meantime, I'll continue to dig around. As stated above though, a work around would be to declare named methods instead of anonymous functions and this work around is only required if an inherited class is trying to execute a callback that was declared via a lambda function in the base class.