NodeCanvas Forums › Support › Setting a Variable works in Editor but not in the Build
Tagged: Build Issue
So i have a macro which has input variables and 2 float output variables which i use to change the bb variable of the FSM. FSM has 4 flow script states. Inside 2-3 of these flow scripts i have this macro doing some changes to the variables. The variable change is dependent on a node that i made myself. What could i be doing wrong?
ProgresserNode.cs –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
using System.Collections; using System.Collections.Generic; using NodeCanvas.Framework; using ParadoxNotion.Design; namespace FlowCanvas.Nodes { [Name("Progresser")] [Category("Value Manipulator")] [Description("Change the value based on incrementation.")] public class ProgresserNode : FlowControlNode { public float output_progress = 0; private float output_percentage = 0; protected override void RegisterPorts() { var input_progress = AddValueInput<float>("Progress"); var input_minValue = AddValueInput<float>("Minimum").SetDefaultAndSerializedValue(0); var input_maxValue = AddValueInput<float>("Maximum").SetDefaultAndSerializedValue(1); var input_increment = AddValueInput<float>("Increment").SetDefaultAndSerializedValue(0.1f); var input_isForward = AddValueInput<bool>("Is Forward").SetDefaultAndSerializedValue(true); var flowOut_Progressed = AddFlowOutput("Progressed"); var flowOut_MaxReached = AddFlowOutput("Max Reached"); var flowOut_MinReached = AddFlowOutput("Min Reached"); var flowOut_InvalidMinMax = AddFlowOutput("Invalid Min Max"); bool isMaxReached = false; bool isMinReached = false; AddFlowInput("In", (f) => { if (input_maxValue.value < input_minValue.value) { f.Call(flowOut_InvalidMinMax); } else { if (input_isForward.value) { if (input_progress.isConnected) { output_progress = input_progress.value + input_increment.value; } else { output_progress += input_increment.value; } } else { if (input_progress.isConnected) { output_progress = input_progress.value - input_increment.value; } else { output_progress -= input_increment.value; } } if (output_progress > input_maxValue.value) { output_progress = input_maxValue.value; isMaxReached = true; } else isMaxReached = false; if (output_progress < input_minValue.value) { output_progress = input_minValue.value; isMinReached = true; } else isMinReached = false; output_percentage = (output_progress - input_minValue.value) / (input_maxValue.value - input_minValue.value); if (isMinReached) { f.Call(flowOut_MinReached); } if (isMaxReached) { f.Call(flowOut_MaxReached); } f.Call(flowOut_Progressed); } }); AddValueOutput<float>("Progressed Value", () => { return output_progress; }); AddValueOutput<float>("Percentage", () => { return output_percentage; }); } } } |
I changed my progresser node to this and it seems to have fixed the issue.
I am investigating further but if anybody know or have an idea of the cause of it, i would be glad to know.
I was using ValueInput<float> for progress float. And i switched it to BBParameter<float>. And honestly this works much cleaner but still the cause is important.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
using System.Collections; using System.Collections.Generic; using NodeCanvas.Framework; using ParadoxNotion.Design; namespace FlowCanvas.Nodes { [Name("Progresser")] [Category("Value Manipulator")] [Description("Change the value based on incrementation.")] public class ProgresserNode : FlowControlNode { public BBParameter<float> progress; private float percentage; private FlowOutput flowOut; private FlowOutput reached; private FlowInput flowIn; private ValueInput<float> input_minimum; private ValueInput<float> input_maximum; private ValueInput<float> input_increment; private ValueInput<bool> input_isReverse; private ValueOutput<float> output_progress; private ValueOutput<float> output_percentage; private void CalculateProgress(Flow f) { float change = input_increment.value; if (input_isReverse.value) { change *= -1; } float beforeChange = progress.value; progress.value += change; float afterChange = progress.value; percentage = (progress.value - input_minimum.value) / (input_maximum.value - input_minimum.value); if(afterChange > beforeChange) { if(progress.value > input_maximum.value) { progress.value = input_maximum.value; f.Call(reached); } } else { if(progress.value < input_minimum.value) { progress.value = input_minimum.value; f.Call(reached); } } f.Call(flowOut); } protected override void RegisterPorts() { input_minimum = AddValueInput<float>("Minimum").SetDefaultAndSerializedValue(0); input_maximum = AddValueInput<float>("Maximum").SetDefaultAndSerializedValue(1); input_increment = AddValueInput<float>("Increment").SetDefaultAndSerializedValue(0.1f); input_isReverse = AddValueInput<bool>("Is Reverse").SetDefaultAndSerializedValue(false); flowIn = AddFlowInput("In", CalculateProgress); flowOut = AddFlowOutput("Out"); reached = AddFlowOutput("Reached"); output_progress = AddValueOutput<float>("Progress", () => progress.value); output_percentage = AddValueOutput<float>("Percentage", () => percentage); } } } |
Hello 🙂
Hmm.. In your 2nd node code, I just tried changing the progress from being a BBParameter
Can you please confirm?
Thank you!
Join us on Discord: https://discord.gg/97q2Rjh
But the thing is from a nested flowScript i am changing the progress value as you can see from attached images. And in editor 1st code was working just fine. And all the effect was correct. But in the build it was always staying in the value it left after reaching min/max. Problem is with my node yes, but i still don’t know why would it work in the editor and not in build that’s the problem. Anyways i wanted to put ValueInput<float> cause i wanted to be able to use it in a macro. But now i can only use it directly in the flowScript itself since the reference to parameter of BB is required to be directly set cause i am using BBParameter<float>. I do not want to use System.float since i want to use progress parameter i can reach from other nested flowScripts.
Alright found the problem.
Apparently Port.isConnected only works in editor. Not in the build. So because the value always returns false in Build it always uses it’s own value which after reaching min-max either 0 or 1.
So i added a public bool which says useInputValue if ticked input value is used, if not ticked BBParameter is used for progress calculation.
So how can the script know in build, if the port was connected or not?
Hello,
Indeed, .isConnected only works in the build. This is initially done for performance reasons, but I could make a work around if required to also make it available in build. Truth is, that none of the nodes I’ve made for FC required the isConnected property, but I can understand that there can be some usage for that.
For instance, you could simply change your code from this:
1 2 3 4 5 6 7 8 9 10 |
if (input_progress.isConnected) { output_progress = input_progress.value + input_increment.value; } else { output_progress += input_increment.value; } |
To simply this:
1 2 3 |
output_progress = input_progress.value + input_increment.value; |
If, input_progress
is not connected, then the direct value set in the inspector of the node will be used, which can of course be left to the default zero. The whole concept here, would be to automatically use the connected value if there is indeed a connection, otherwise use the directly set value instead 🙂
Having said that and as stated above, if you want I can take a look at making isConnected
available in build as well.
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh