How to keep a slider position?

Hey guys, basically im wonder how to keep the slider position when you leave and re-enter the menu. The sliders keep resetting back to 100%. Any help would be really appreciated! :slight_smile:

Set/Get the slider’s variable in your game instance BP, and then set the variable in widget with EventConstruct so that it refreshes the slider every time it is shown on the screen.

Any chance of a image with how to do that? This is my first time doing anything like this, Thanks in advance!

Create a variable in your game instance BP(it is a string in my case. You can make it a float if you like) and then call and set it in your widget BP like so:

Then in the widget BP again, call and get the variable to set the slider’s value:

Game instance will pass the variable between levels as long as the game is running. Of course, if you want to save the slider position and the value after you restart the game you need to create your own save system.

Oh wicked thanks alot! How do you call the variable from the game instance BP to the Widget BP?

Drag from the blue pin of Cast to gameinstance node and type the name of your variable. You’ll see Get and Set nodes in the list.

I think i have it right? :slight_smile:

Ok good news i have it working (sort of) thanks to you! Really appreciate it! Its saving the percentage of what they were set to, but the marker on the slider is going back to the same position

Are you setting the slider’s variable with Event Construct? You need to do that so that it gets the saved value from game instance every time you open the widget.

Yeah i am pretty sure i have it exactly like you do :frowning:

Hmm, there may be a problem with your mapping values then. Actually you dont need to use map Range if the value you want to set is 0 to 100; in which case you just need to divide it by 100 to get a value between 0 and 1 for the slider.

yeah i ended up removing them so the value was just 0.0-1.0, tried messing about but the marker on the slider just keeps resetting to 1.0, really odd because the values are basic enough

Can you post a screenshot of that part please?

I’m not sure what the problem is. It should work just fine as long as the float variable you are setting/getting in game instance is in 0 - 1 range. : \

Yeah i dont get it either :confused: , could adding, on mouse capture end have anything to do with the final position of the marker after you let go of it? Or maybe some boxes on the variables need to be ticked?

No, just OnValueChanged should be enough. You need to go through those variables again and make sure everything is set in order i guess.

Btw, you dont need to get game instance > Cast to separately every time you call those slider variables. Get game instance > Cast to yourgameinstance > get slider position 1,2 and 3 from the same cast.

Just to give you an update and anyone whos looking at this for answers. I got it working. I didnt bind the actual slider to the variable! that is all i missed out! Once again thanks alot!