i tried to use GameInstance to do that, but i failed.
i can use GameInstance to load game from the level in which i save my game.
but i cann’t load game from another level.
Loading a new level, doesn’t change the value of any of your variables defined in the gamemode or gameinstance, unless you do it. After you load a new level, you just pass the values of health, score or whethever to the hud.
If the values are been resetting, the the problem is with your logic.
How are you loading a new level?
Are you spawning a new player?
Where are the values of score, health and such, stored?
Who controls the HUD?
thanks all of you ,and i tested GameInstance from a new project, as you say, the value of my variables defined in my GameInstance doesn’t change.
(i don’t either forget to set the gameinstance in the project settings:),anyway, thanks for your recommendations )
so it is the problem with my HUD.
you can see the photo, when i try to cast to mycharacter, and it fails in my UI_MainMenu.(inside my UI_MainMenu, it has a button called “ContinueGame”)
now i know that the values in my GameInstance will not change. and the values in my character will reset when i change the level.
so i want to find a way to put the values in my GameInstance to the values in my character when i change the level. i have tried my best to do it, but i didn’t resolve it…
Why not keeping all the values you need to keep in the GameInstance?
But if you want to transfer them from gameinstance to player, then all you need is to create a function or custom event in the gameinstance to copy those values:
You can also create a function to copy from player to gameinstance, and call it before the level change.
Note: there’s too much duplication. If you don’t want to use gameinstance as the tracker, then I suggest you use slots to save and load the values between levels. This way, you can discard gameinstance.
now i finally find out why i can’t cast to my character. because in my start level,the mode of game is different from that in my play level. so that’s why i cann’t cast!
now my problem is resolved, anyway ,thanks for your help, thanks for your teaching!