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
2.01k stars 414 forks source link

Node creation issues #72

Closed aphex- closed 7 years ago

aphex- commented 8 years ago

Hey,

If I open a Node Editor window with an empty canvas the Create method of all my custom Nodes get called. I wonder why this happens on an empty canvas. If I add a Node by hand (right click => add) the Create method is called as expected. Afterwards the methods Calculate and NodeGUI are called. The problem is that the node.GetInstanceId() is changing between Create and the other methods. This explains why I am loosing references to some custom private members that I set up in the Create method. Is the Node instance copied somewhere? Is this a bug or the expected behavior?

Sorry if this is not the right place for such questions..

Seneral commented 8 years ago

It's 'expected' behaviour, it is caused of a somewhat weird implementation I admit, but it was a design choice I made back when I had less experience with C# (this project is now over a year old!). I think I made this decision because I couldn't make the Create method static for some reason, probably because of inheritance and overriding, and so what I did was I created an 'invalid' default instance of each node on initialization (cringing when I think back), which will be used to create the other nodes. So these nodes are the cause for the Create method called at initialization... I agree this is is something I'd like to see changed in the future... xD

Seneral commented 7 years ago

Btw, the initial problem you described is fixed with 8b2caaa, Create is not called anymore on each initialization for each node. The design issue is still existant though so I'll keep this open.

Seneral commented 7 years ago

Ok, finally completely eliminated with the latest modifications to the knob system and making the node property-based:)