I have a character creation Widget with sliders for attributes. That data get stored in a SaveGame blueprint. Then on my 3rd person character that data gets called with an Event Tick, that way it allows the player to adjust their attributes in-game to decide how they’d like to build their character. Let says the player has over 100 variables that can be adjusted; will using an Event Tick on the Character blueprint impact performance later on, say this is going to be a multiplayer game? If so, is there a better method to set this up? I don’t want to get too far in to find out I have a lot of re-work to do…
The reason that I used a tick is to allow the user to play a level, check how their character is setup, and make changes accordingly. I need those changes updated in real-time so they can go back and forth; from the level to the character creator widget and back again. If I dont use a tick, the variables on the 3rd person blueprint don’t get updated when they make their changes.
Yep you only want to use a tick if you want the value to change constantly. You want to setup those attributes once, then just change them when the user interacts to make a change. Definitely don’t want to be changing them every tick
The way I would do something like this is make a bunch of custom events in your character blueprint and make a save button in UMG aka the character creation widget.
Lets say the player makes changes to his character in the character creation widget. Well then we simply call the custom event in your character blueprint (from the character creation widget) that gets the values he/she made in the creator widget and sets those values to corresponding variables in the character blueprint when you press the save button. You can achieve this by casting to the character blueprint from the OnClicked event for your save button. And then calling the variables in your widget blueprint by dragging off of the cast to node and make the changes there, or as I mentioned use a custom event to parse the data through to the character blueprint. (you can add inputs/outputs to a custom event)
This custom event can now be called anytime your player makes and commits his changes by pressing the save button, which means it wont execute and store the variables every tick, but instead only executes when its needed/called.
Let me know if you need some visuals if you cant get it to work.
Here is what I have so far. I dont think Event Begin Play is where I should have my Call Custom Event hooked up. I need it to be checked every time I make a change and hit the Save button. How I get that to Call every time I hit the Save button?
I am no UMG expert but I believe there is an event you can call for sliders, simply select your slider and call one of these:
I believe you need the bottom one. Use that instead of your tick for setting the variables in your Widget blueprint.
Then on the Save Button you can also select an event, this time called OnClicked. When OnClicked fires you will want to Cast to PlayerCharacter blueprint to call a* Custom Event *you have to make IN your PlayerCharacter blueprint first.
By selecting the Custom Event node in the PlayerCharacter blueprint you can add Inputs which have to have the same variable types as the variables you set in your Widget Blueprint.
Now in your Widget Blueprint you can drag off of the Return Value of the Cast to PlayerCharacter node and type in the name of your Custom Event in your Character Blueprint. Once placed you can hook up your variables.
The buttons I have no problem setting up. But should I use Get Player Character > Cast to PlayerCharacter > Call Custom Event within my SaveGame BP? I want all of my settings stored somewhere.
In my PlayerCharacter BP I have my custom event setup, and I’m assuming it’s taking the data from the Widget or SaveGame file and importing it (depending on how I set it up). Next I call my Custom Event, but what do I hook that up to since it has an input/output Exec pins. Don’t they need to be triggered?
Looks like I can’t Get Player Character > Cast to PlayerCharacter > Call Custom Event within my SaveGame BP. The idea is to pull the data from the SaveGame BP so when the player starts the game at a later time, all his setting are correct. If I Cast from the Widget to the Player BP, it seems like Im bypassing the save game portion.
That is correct. With the setup I provided you are indeed bypassing your save game portion which isn’t what you wanted. I apologize I misunderstood your original intention.
To be honest I don’t have alot of experience with SaveGames as I develop most of my stuff to work with databases but here’s the order of events a setup like this should follow:
In your Widget Blueprint (which I assume is the first thing the player sees when starting your game)
Check for slider values using the OnValueChanged event provided in the image in post #15 and set them in variables in the widget blueprint.
Once player is done making changes and presses the Save button, execute an OnClicked event for that button.
The OnClicked event should store all the variables in the SaveGame you create there and then. (Unfortunately I cannot help you with storing variables to a SaveGame)
Make the player possess the CharacterBP.
In your CharacterBP
5a. On EventBeginPlay for CharacterBP load your SaveGame (again I don’t really know much about SaveGames, there are probably some checks you would want to do at this part) which contains all the stored variables. This is mainly used for when the player exits the game and when playing again having the changes he made during an earlier session available because they were saved. 5b. If the player is doing making changes, and wants to play after that, you also need to do a SaveGame but this time you fire a Custom Event that applies the variables in the CharacterBP. This will allow your player to switch between Character creation and the game itself. Read the Going back to the widget section
6. Either access the data in the SaveGame to pull all the stored variables out and either set them again, only this time in your CharacterBP, or apply the changes directly to - I presume - the character’s mesh. Or use the Custom Event if the player switched back to the Character Creation widget and now wants to resume playing.
Going back to the widget
If you want the player to be able to go back to Character creation/customization you have to set the variables you’ve loaded from the SaveGame in the CharacterBP. This is where you could use a Custom Event to send those set variables back to the widget, so the player can edit them again. Once he’s done he is going to press the save button which will save the variables to the SaveGame again > Here you’d need custom event for receiving the changes that were made to the variables during runtime in the CharacterBP which will be called when it isnt the first time the character creation widget is visible for the player. (since you used EventBeginPlay in step 5a you have to have an alternative way of loading these variables onto your character during runtime, because EventBeginPlay was already fired.)
Hope this helps somewhat, let me know if I mistunderstood your intentions again. It’s getting late and I’m not 100% sharp anymore
haha no worries. I have all of this already working. The problem is that I dont know how to setup my Player BP to “refresh” those variables without using an Event Tick. I need to somehow setup my Player BP so that when the SaveGame get changed (one or more variables) my Player BP will update.
Check my post again I made some changes to it. What you’re describing is done with the Custom Event. I believe your setup requires both the loading from a SaveGame and a Custom Event to get the desired result.
You could do the logic to choose between which one to use by setting a boolean to true after the initial EventBeginPlay. The Custom Event will get fired when this boolean is true, if false it will do the load from SaveGame one.
Note: In both scenarios you need to save the variables to the SaveGame for when the player suddenly decides to stop playing.