ShowFPS Problems! (How to make ShowFPS NOT FLIPFLOP???)

I’m trying to set up a bool which loads and saves. This bool will set “Show FPS” to true or false.

The problem I run into is:
Trying to use the same console command “showFPS” makes it flip flop.

When I load, whether or not the bool is true or false, “showFPS” will just flip flop.

Basically I want to be able to set “showFPS 1” or “showFPS 0”

Is this possible? Or is there another way I can allow the FPS to be seen or unseen in UMG?

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.

As for the second point, here’s a custom FPS counter you could use:

I’ve been trying for some days now and I don’t want to suffice with anything other than showFPS :slight_smile:

Ok, in this example I’m using the 3rpderson template.

Open the ThirdPersonCharacter blueprint.

Create a new function (hit the plus sign next to functions)
Call it “toggleFPS”
Add this logic:

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:

I forgot to say, when adding the logic, that you need to add a boolean variable. I’ve called it “FPSIsVisible” in this example.

Now all you need to do to figure out if the FPS counter is visible, is check if the boolean is true.

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.

Right-o. This actually makes more sense for me right now.
BUT I did mention that I want to use an Apply button in my first comment to you.

OnValueChanged would be so easy, but how can I detect if the value has changed before I hit apply?

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.

So this is what I did:
Create Function
Load, Apply, Save
But on Apply button it always flip flops

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

Sorry I wasn’t behind a computer for a while.

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?

Thx if you can

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?

You would save the UMG checkbox bool - because you only want to know what the users’ preference is.

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.

Have you tested with a custom button, instead of doing it “OnValueChanged”?
You might see the error I’m running into.

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?