How do I make a button add a value to a counter?
I have a game where you are given options In a widget by clicking on buttons that take you to the next scenario. How can I make it so every button has a coded value and it adds them all up at then end. For example level 2 option 1 has a value of 30$ and option 2 has a value of 10$ After the player completed the level I want that value to be added to the total so on final screen it will read how well the player did playing the game. I have been trying for a few weeks to figure it out. Any suggestions?? Or Help?
asked Mar 23 '16 at 04:15 PM in Using UE4
You need to create your own GameInsatnce and there you need to create the counter
To configure your GameInstance you should go in settings -> maps and mode ( there are lots of information on internet )
To access the gameInstance you can simply call GetGameInstance node an cast to YourGameInstance
GameInstances are used to save data between levels. Any other 'files' are reseted after loading another level
So I guess this was your problem: when you load another level, the counter was reseted to 0. Am I right ?
How would i configure the counter within the Game Instance
answered Mar 25 '16 at 05:19 PM
First, create your own Game Instance Class. The Game Instance Class is used to store Data between Level-Changes.
Open your newly created Game Instance Blueprint and add a new Integer Variable called Counter.
Then, right-click into the Event Graph of your Game Instance Blueprint and search for Custom Event. Select that and name the new Event IncreaseCounter. In the options of this Event (select it to see them on the right side), add an Input of Type Integer and name it InValue. Then do the following:
You can use this Event in your Widget to increase the Counter Variable that is placed in your Game Instance class.
Now you need to set this Game Instance Class is the default one that the Game should use.
Open your Project Settings by clicking on "Edit -> Project Settings" in the Main Editor Window.
Click on Maps and Nodes and select your Game Instance Class in the bottom most Drop-Down Menu:
Now, in your Widget (or where ever you want), you can call Get GameInstance, cast it to your custom Game Instance Class and call Increase Counter.
That should do the trick. If you still need help, i HIGHLY recommend to watch/read some more tutorials (:
answered Apr 18 '16 at 01:10 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here