I trying to build a save system where I store level name, player inventory and transform etc., in a save object through the game instance, when I press a certain key.
Now, after I save in a certain level and then travel to a different level (open level), I then try to ‘load’ my save through an event in the game instance like so: open level (level name being the one I saved before), and then get player character and try to apply all data saved before to it, like inventory, transform etc.
Now the problem is that the saved data doesn’t get applied to the player, unless I put a delay immediately after the open level node.
Thing is, as soon as I hit that ‘load’ key, I can actually see, for a split second, that the data is applied to the player (I’m getting transported to the place I was when I saved), but it then resets immediately to the default player spawn point in that level, with no inventory etc.
I don’t know if it’s because the saved data gets applied and then overwritten once the open level reinitializes everything, or if the player character doesn’t load fast enough, hence the game instance has no player character to apply that data to?
If someone can explain what’s going on and what’s the proper way of doing this. Thanks.
By default, the game mode spawns the player at the player start. If you want to take control, you’ll need to set the pawn type to ‘none’ in the game mode for that level, then you can spawn and position the player at your leisure.
Yes, I’m calling open level in GI, and then the rest of the functionality after that, as well in the GI, like changing the player transform.
Are you saying that the gamemode resets the player character?
Is there any documentation on what the game mode does exactly, in depth, anywhere? The official documentation is basic.
Thanks. I’m not sure which of the 2 options is better. If I were to wait until the player is spawned, and then reposition it, where would I go about doing that, and how would I know when the player has finished spawning/initializing? Because right now I’m doing it in the GI, immediately after open level, and it doesn’t work. I chose the GI because I have the rest of the save functionality in there, not wanting to spread that over multiple blueprints too much.
Well, it still doesn’t work. When I ‘load’, I run all the saved data through the player character blueprint to make sure it’s loaded so it can run. So far so good.
As soon as I introduce that open level node, it doesn’t work anymore. I tried putting it in the player character, in the player controller, and in the GI, all by itself with no other code to follow. No go.
I cannot believe there isn’t an easy way of applying your saved data after opening a level. What game doesn’t have that? Surely, there should be a simple way of doing this.
Yes, that’s what I’m doing, but doesn’t work. Don’t know if I should use level streaming instead. I heard some people saying lighting can spill in from another level when baking. So I’m a bit reluctant to do that.
Yes, I did that too, but still didn’t work. I think the code after open level runs, but somehow there’s no player character object at that time?
If only there would be an in depth source on the order that things run in and how.
Yeah, having the player do all the work, aside from opening the level, does work. The only problem is that as soon as the player spawns in the level it applies the saved data regardless if you want it or not. But I guess I can just put a condition in the GI for that.
I know delay in the GI or controller also works, but delay is a bad way of doing it, because you can never be sure the delay will be long enough in all cases, so that’s why I wanted to avoid that.
Thanks a lot for the help.
The delay is only to get the thing working at all.
In any event, you can save a flag ( also in the save game ) to tell the player whether to load or not. But, you still get a ‘jump’ on repositioning.
The smoothest way, is to just spawn the player in the correct location ( from the save game ). For that, just make sure you have no pawn specified, and the GI can just do the spawn and possess.