Seneral / Node_Editor_Framework

A flexible and modular Node Editor Framework for creating node based displays and editors in Unity
https://nodeeditor.seneral.dev
MIT License
2k stars 415 forks source link

OnRemoveConnection #194

Closed beddowdm01 closed 3 years ago

beddowdm01 commented 3 years ago

Needed a way to override OnRemoveConnection from a class that inherits from Node like can be done with OnAddConnection. Small change but makes it so much nicer when I need to add functionality when a connection is removed.

Seneral commented 3 years ago

Sorry for the late reply. Thanks, no idea why I added OnAddConnection but no remove equivalent. Just one minor change if possible, for consistency and runtime.

Seneral commented 3 years ago

Actually, there are two other things, sorry I didn't see it at first. First, right now the callback will get the parameters switched, since you're calling it on the connections body. Second, both port bodies will want the same notification, so we'd need another line:

this.body.OnRemoveConnection(this, port);
port.body.OnRemoveConnection(port, this);

If in your case the callback should only be received on the one side (e.g. only on output ports), then you can do that by checking the port directions. Other than that there is currently no guaranteed order on which port the connection is removed from.

beddowdm01 commented 3 years ago

Yeah, makes sense! Apologies for overlooking that :)

Seneral commented 3 years ago

No worries, same for me, thanks for the contribution!