Instead of calling the console command on Begin Play, use a function that adds some logic before calling the command.Then, when the function is called, flip a boolean var to 1 so that you know it’s on.
Next time the function is called, flip it to 0.
It’s not exactly the answer you are looking for, but if you keep track of every call, it should solve your problem. You can simply read out the boolean to see if the FPS is visible or not.
Additionally, you can do your own calculation of event tick and delta time to create your own FPS counter in a BluePrint Widget… although it would be just a touch slower than the engine one.
Now, go to the Event Graph of this blueprint.
Add “key F” as an event (to make sure the FPS toggles when we press F) and wire the “pressed” action to your ToggleFPS function, like so:
Ah ok, so you want to do it in the widget. It’s pretty much the same. Instead of creating this function and boolean on the player, add it on the widget. And, instead of calling it with the F key, call it when the checkbox changes.
That’s the logic for in-game. Now the logic when the game starts:
I’m assuming you are already saving the value of the checkbox (using SaveGame node, or whatever) when the game starts up again. Then, on Begin Play, check that variable, set it to the checkbox (true/false), and call the function again.
I have logic for Load, Apply, Save.
But when I hit Apply button I have to make sure the checkbox value has changed. Otherwise, it will fire again possibly making it show/disappear when it should have done the opposite.
The apply button doesn’t really have to check if any values have changed. You just check if the value of the checkbox (after hitting apply) is the same as the boolean you use when flipping the FPS on or off. If it’s not the same, call the function. Else, don’t do anything.
It doesn’t matter what the value of the bool is lol…it will ALWAYS do the SAME console command which just flips it… what a bummer man
It doesn’t even load properly because this bool doesn’t mean anything
I don’t get your logic. You don’t need the bool. You need a flip flop. And it doesn’t do anything except on load → not do what checkbox says.
On apply → not do what checkbox says
Correct, the checkbox is a bool itself. However, the “show fps” command doesn’t have an on/off switch, so you have to keep track of it being toggled yourself. That’s why I recommend wrapping it in a function and using a boolean (as shown in my screenshots) to see if the FPS counter is on or off.
Now, when your UI changes and you press Apply, you can check this boolean to see if the UI is on or off and flip it accordingly to what the user put into the UI.
I tried but I have failed. Can you show me directly with a checkbox in UMG?
I assume it would work with “on startup, load saved bool” (since the function makes the check??)
Just let me know which bool to save! Is it your bool or the UMG checkbox bool?
A BIG thing is the Apply button. I’m able to check the box before I hit Apply. So my logic there didn’t work out. Idk how you managed to do it. I edited the comment before this if it makes sense, lmk?
I save and load it just fine. But your function uses a totally separate bool.
Also I can change the checkbox to true/false before I hit Apply, which messes things up.
I didn’t test this code, but here’s how I would do it. This blueprint is a widget with a checkbox and apply button.
I’ve added two functions: saveVariableToDisk() and loadVariableFromDisk() where you would do your saving and loading.
the toggleFPSVisibility() function is the same as above, but in the widget this time.
The rest should explain itself. Let me know if it’s unclear?