Reply To: "Default value for parameter", serialization, and 2.7 / 2.8 differences

FlowCanvas Forums Support "Default value for parameter", serialization, and 2.7 / 2.8 differences Reply To: "Default value for parameter", serialization, and 2.7 / 2.8 differences

#1781
Gavalakis
Keymaster

Hello!

First of all thanks for the detailed and thorough posts.

Indeed, in v2.8 default(T) values are no longer serialized to save up on performance. Basically, the important piece of code for this change is in FlowNode.cs line #75, where it reads if (!port.isConnected && !port.isDefaultValue){. Removing the !port.isDefaultValue will basically revert to how it used to work in 2.7.

Avoiding serialization of default values is something good generally speaking. Based on your posts though, I understand that the ability to provide custom defaults can be quite useful as well. Thankfully, after a few minutes of thought, implementing this seems quite easy, albeit you will need a few changes to your code though.

—1st Solution—-
For the implementation, please open up Ports.cs file and at line about #300 of the ValueInput class..

1) Add this piece of code:

2) Replace existing isDefaultValue with this:

That’s basically it 🙂
Then within your nodes, instead of setting/using serializedValue, use defaultValue instead:

– Custom default values set, will now show in transparent grey as well, instead of only default(T).
– Changing the defaultValue of a node of which it’s serializedValue has not changed for example from within the inspector, will also propagate the default value. What I mean is, that in the above example the string defaultValue = "Hello". If we add a bunch of TestNodes in a graph and do not change their string value input from inspector for example and at a later time the node implementation change so that defaultValue = "World", all “untouched” nodes will also change their input to the new default “World”. Now, this last part might not seem ideal.

—2nd Solution—-
Another completely different solution (disregard all the above, would be to set the serializedValue in the OnCreate method callback (this is what is actually done in SimplexNodes). This is naturally only called when the node is created (but after RegisterPorts).

—3rd Solution—-
Lastly, the simplest of all solution, would be to simply remove the !port.isDefaultValue in FlowNode.cs #75, which is basically how v2.7 worked before.

Please let me know what you think on the above. Does the 1st solution sounds good to you?
Thank you!

Join us on Discord: https://discord.gg/97q2Rjh