Pass variable between main menu and levels
Hello i need help passing variables... i dont know how:
1- I have a main menu widget, where i can select the level of difficulty ( hard, medium, easy).. and i want to pass it to my character or enemies in the level played ( have more speed, or anything that could modify the difficulty).
2 - I need an easy way to save health, ammo and bombs and pass to the next level. Ex if i only have 3 ammo left, i begin the second level with 3 ammo left, not plenty of them ( the same happens with health and bombs) .. When i open a new level i begin with initial quantity of them ( ex: 10 ammo, 3 bombs and 100% health)..
Thanks in advance
I said yesterday you can use the Game Instance and this is how you do that:
A very important thing to remember after you create your game instance is to tell the engine that you want to use this particular instance. You do that in Project Settins (Project Settings in the Edit menu). Choose Maps and Modes and you can change the instance here:
In your menu widget you need to store the information in the game instance variables before you load the first level. You can do this by casting to the Game Instance and send the information to it. It the following example I do this when the player clicks the play button:
To get to the Instance variables drag a wire from the blue pin on the cast node (As MyGameInstance) and open Variables in the menu. You should have access to both Get and Set versions there under the Default category (Context Sensitive must be switched on):
The final step is in your level (either level blueprint or regular blueprint class). Repeat the casting and Get the variables from the Game Instance. And remember to create the variables you need in your level or class blueprint!
Hope this helps! Ask if you have questions or trouble.
answered Jan 16 '17 at 10:26 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here