How Do I attaching my save and load functions to buttons?

So I am having some problems I was able to put together a simple save and load system that stores the users location

The user can hit G to save the game and K to load the game

But I want to hook the save and load function’s up to UMG Buttons

The Save button is in the pause menu which can be bought up in-game by the user when they hit 0, while the load button is on the main menu which is separate from the player level

Right now I have all the save and load functions inside the Character Blueprint in my case it is called Gemini,

Heres what it looks like

The Save

The Load

And my save game (TwinDarkness_Save) that has one variable to store the user location

71250-savegameobject.png

Any help you can give in hooking these functions to the UMG buttons like I described would be great

I am still new to unreal so forgive me if this is an easy question

You should copypaste your code in a function library so you can call it when you want using the specific node.

For example, instead of build your code in your char’s BP you can create a new function library called “Banana”, create a new function called “Peach” with your save code and an other function called “Berry” with your load code. If you do this (as you can imagine the names aren’t important) you can call Peach and Berry functions where you want in your project. OFC you have to get a transform variable in input for saving and a transform variable in output for loading (for correct data transfert).

Sorry for my english, I hope I was clear! If it didn’t help you make me know, I’ll try to be more specific.

I’m sorry I am still very new to unreal engine 4 so I am not to sure how to do what you suggested, Im not even sure I know how to create function library is there any way you could provide some examples ?

Create Blueprint Widget, drag in a button for Save and a button for Load. Click on each button and in the Details panel on the right, scroll to the very bottom and select OnClicked or OnPressed. (OnClicked is fine for PC, OnPressed is fine for mobile device).

Then go to the Graph of the Widget once all buttons have been added and the red Events OnClicked/OnPressed have been added to the Graph.

Copy your save sequence of nodes and attach it to the OnClicked(Button for Save).
Do the same with load sequence of nodes and attach that to OnClicked(Button for Load).

Then in the level blueprint of whatever level you want to have those buttons available to be presed to save and load, connect these nodes in sequence to an EventBeginPlay(Will display the buttons to be pressed right on level startup):

CreateWidget (In Class select the Widget name that holds those buttons and the sequence of nodes that are inside the graph of that widget) —> AddToViewPort (Connect return value to target) —> SetShowMouseCursor and connect a GetPlayerController (return value to target)

Then instead of a function, I use a Custom Event. I create a Custom Event Save and Load inside my widget blueprint and inside my level blueprint I can call that event to save and load, once the buttons are pressed.

Ok, step by step:

  1. Right click in your content browser and select Blueprints → Blueprints Function Library.

  2. Rename and open it.

  3. Rename NewFunction_0 in “SaveCharTransform”.

  4. Look for the inputs and click on “new” button.

  5. Change variable type to Transform (the orange one) and rename it.

  6. Copy your SaveGameV1 code and paste it inside your new brand function.

  7. Instead of your “make transform” node, link to the “PlayerTransformSave” variable your Transform Input pin.

  8. Compile&Save

  9. Get back to your character BP and try to look for SaveCharTransform, you can now call this function with a transform pin.

  10. Connect the Exec flow from event to your new node.

  11. Link your “make transform” node to the SaveCharTransform transform pin.

Done

I have got to step 6 but have hit a wall when I am creating the save game object it wont let me prompt the return to a variable ?

which is stopping me from continueing on since I cant import my savegameV1 code

I already have the buttons made and know how to add functions to them here they are

And here is the other one

its transfering my code form the character bp to the buttons that is giving me all the problems

Since it wont let me use get actor and make the transform the way I did

Heres what I have so Far

Ok, I post you the solution, now with 100% more imgs!

71268-fl3.png

If not here you are an other solution!

Thanks for the screenshots but I dont think this is what I am looking for I just want to let the user press the two UMG buttons I have made to save or load the game

I dont want them to have to hit G and K ever

“Since it wont let me use get actor and make the transform the way I did”

Use a cast node to your character class, connect the “Get player character” to Object node, then you can take all the info from your char.

Well I have it half working the save function now works from the pause menu

Just cant get the load working

For the load: you can call the “Set Actor location” node from your character Cast.

I have tried that but to no look this is what i have so far

The level opens but the character does not load to the new position

Any Ideas why ?

Because when you open a new level the Exec flow is stopped. You should pass your data via function or via Game Instance to the new map.

how does one do that ?

Is pretty complicated if you are new to the engine, I’m really tired. If you can wait tomorrow I’ll reply with a pretty exhaustive explanation via answerhub or youtube video.

I look foward to it, thanks again

could u provide a little more detail ? than just create blueprint and search like how do I connect them up etc ?

Create Blueprint, search for the term Game Instance and select that. It is a very clean way of saving all variables that should be kept like using variables in widgets and transferring the values to level blueprints.