Unsubscribing an event that returns a value before returning?

Is it possible?

Not quite sure what you’re going for here - got a code sample of what you’re doing and when you want to unsubscribe?

1 Like
EventManager.SomeEvent += DoSomething;


bool DoSomething()
{
EventManager.SomeEvent -= DoSomething;
return false;
}

that already works:

private Func<bool> SomeEvent;

private void Start() {
    SomeEvent += DoSomething;
    Debug.Log(SomeEvent == null); //returns false
    Debug.Log(SomeEvent());       //prints false
    Debug.Log(SomeEvent == null); //returns true
    Debug.Log(SomeEvent());       //throws nullreference
}

private bool DoSomething() {
    SomeEvent -= DoSomething;
    return false;
}
1 Like

Great. Thank you!