Is there any potential problem if I bind to a widgets event dispatch, but I do not ever explicitly unbind?
In this particular case, shortly after the bound event fires, I remove the widget from parent. I think that should nullify everything and the binding would be garbage collected, I guess?
I haven’t seen any problem, but I figure if there is an Unbind function maybe it is there for a reason.
No worries @BIGTIMEMASTER, everything is fine! The Unbind node is if you want to remove a bound event from a dispatch Say you want something to only happen on the first event dispatch but never again, you’d unbind it at the end of the event itself so it won’t happen again. Until it’s possibly bound again.
don’t forget you want to unbind if there’s a possibility that you’ll be passing through the ‘bind’ part again, too. so you don’t end up with the same bind being called many times.
I faced a situation where that was not the case. I have the event dispatcher on my controller that is being called when I press the button. And I have different widgets bound to that dispatcher. When one such widget gets created it binds to that event dispatcher and after it has been removed from parent (not stored in a variable) another widget that uses the same button also triggers logic that existed in the already removed widget. I even checked that there were indeed no widgets in question present in the scene by getting all widgets of that class and printing their amount if any. There were none.
So somehow the widget is already destroyed (but probably hanging somewhere in memory) but its logic is still firing when I call the same event dispatcher for another widget. Maybe I’m doing something wrong, but I found the topic on this forum where people recommended unbinding all events when you no longer need those bindings.
When I did unbindings before removing the widget from parent the issue disappeared.