One thing I find my self doing is the following structure.
[Meta(typeof(IDependent))]
public partial class Foo: Node
{
[Dependency]
public Bar Bar => this.DependOn<Bar>();
private bool IsResolved { get; set; }
public override void _Notification(int what)
{
this.Notify(what);
}
public void OnResolved()
{
Bar.SomeEvent += OnSomeEvent;
IsResolved = true;
}
public override void _ExitTree()
{
if (IsResolved)
{
Bar.SomeEvent -= OnSomeEvent;
}
}
private void OnSomeEvent() { }
}
Foo wants to unregister events from a dependency when it's removed from it's parent, but if it's removed before OnResolved() is called it might result in errors due to an unresolved dependency. So I have found the need to add a bool property to check if OnResolved() has been called.