0
Under review

Save/Load Challenges

Jacob Falling 4 months ago in Game Creator updated by Marti (Lead Developer) 3 months ago 9 1 duplicate

Hello!

I've had some difficulties with loading a saved game, mostly involving inconsistencies in data preserved after load:

  • Player Stats not preserved
  • Player Transform not preserved
  • Player Inventory not preserved
  • Player not equipping items
  • Player equipping incorrect items

Some of this I've been able to resolve, though in any case I'm not firmly convinced that my solution will be viable as the game scales. Largely, this has been done by ordination and delaying of the On Load actions needed to set the UI, active/inactive/destroyed objects, and otherwise preserve the world/play state. I now have a wait at the beginning of the On Load actions that has to be 3-5 seconds for any success.

It would appear that the On Load Trigger does not wait for the equipment of Inventory, UI display of stats, and other elements to complete. If I do not put the time delay at the start of a set of actions from an On Load Trigger, these begin to fire, and seem to interrupt or contradict the automated Load functions for the above.

For instance, I can effectively watch while the player dresses (equips meshes) after the scene loads.

Interestingly, Global Variables seem to be always preserved, but I imagine these are among the first elements to be loaded.

And one aspect that I have been completely unable to resolve is the Inventory/Equipment issue. As noted above, the instantiation of equipment takes time, and even then, the Player for some reason ends up wearing the equipment that was initially placed in an equipment slot, rather than the equipment that replaced it and was worn at the time of saving.

In fact, if I remove that item from the player's inventory before saving, the game freezes completely on loading.

Does or should the On Load trigger occur after all reliant modules have completed their functions or co-routines?


Is there any way to determine what length of delay is needed for the automated load to finish, particularly as the game scales?

Is there an issue with subsequent equipment in the same Inventory slot not being preserved?

I haven't replicated in a clean project at this point, as it's obviously a complicated scenario.

Here is my console after saving once and then loading. Curiously, there are two save comments but no load comment.

I need to track down the missing reference exception as well. I was using your script on scene objects, but decided to go another way with that and probably haven't deleted all instances.

I have the save buttons checked where applicable (variables, player, inventory, etc. I'm loading from a separate main menu scene.

Thanks!

Unity version:
2018.4 LTS
Game Creator version:
1.1.8

Duplicates 1

I've made adjustments, but if anything I am seeing even less consistent results.


Here's an example of the inconsistency:


Some loads are less successful. This one loads all the correct inventory on right, and it equips the correct items. But only one of the meshes is actually added to the model.

I get three errors this time:

...but these seem to apply to an image in a separate canvas which actually seems to be loading properly.

Thank you,

Jacob

Confirming that this:

...results in this...


Is something set to autosave somehow? Why would loading a separate scene create a save?


The only place I trigger a save action at this point is much later from a specific point in the game - clicking an object in the game world.

-J

Having the exact same issue. I added new equip slots for leg armor. I have it all working , the problem is it doesn't display when loading the last save, even though the inventory shows it as equipped.

Under review

Sorry for the late reply. Thanks for the tests. I'll take a look at this issue as soon as possible, since seems to be quite breaking.

A few notes though: That message in the console, that says "Saving data (1,1,1)", did you script it somewhere? Game Creator keeps track of data when a scene is loaded. Otherwise, if only the current scene data was saved it would miss changes made previously on other scenes.

Just to summarize the problem, seems like the issue are two mainly: The On Load Trigger being executed too early and the Inventory not loading the meshes (although the items seem to be correctly equipped). Is that right?

Marti,

I think that's mainly it.

I'm consistently getting the "Saving data: (1.0,1.0,1.0) message when loading my main menu scene after my primary first scene:

Start in Main menu (i.e. Scene 0) --> Load Scene 1 --> Load Scene 0 (Main Menu)

I'm not even loading a saved a game in this sequence, only scenes. There is nothing saving at this point, in either an action or a script. Very odd.

It would be nice to understand exactly what preserves between scenes by managers that might not be obvious, so we know what has to be forcibly changed. I'm surprised that audio continues, though it's very nice, for instance, to have the menu title music continue as the game loads!

On the Inventory, I have two items that should be equipped and meshes added, but while both of them are equipped, only one of them adds the mesh. The only difference between them that I can think of is that the mesh that isn't added correctly is in an inventory slot where the character previously wore another item (though not when saving). This unattached mesh can be unequipped and equipped again to add the mesh, but meanwhile she looks as above. Thankfully I had already removed the character's naughty bits, so the screen shots are sfw. :-)

I truly appreciate the work you put into all of this!

+1

I'm attaching a Trigger that should solve the "On Load" Trigger problem. It basically defers the call one frame so that all other callbacks have been executed (Unity doesn't provide easy mechanism to prioritize the order in which scripts are called).

OnLoad.unitypackage

Answering what gets ported, Game Creator basically has a "bag" to collect information on the scene that could potentially be saved. For example, the Player's position and rotation, a chest's content, local variables, ... As a rule of thumb, Game Creator saves everything except for runtime-instantiated objects. For example, if you create an enemy at runtime, this information can't be saved (technical restriction).


So even if you're not saving the game, Game Creator will still collect information from the scene in case you save the game later on.


Regarding the Inventory, I haven't yet been able to take a look at that part, but I don't recall having problems with that. Just a random guess, but could be the cause of the problem: When you equip an item, it goes into a "slot" (called Item Type in the Inventory). However, if an item was present there, it will first unequip that item and equip the new one.

The Inventory examples contain some samples that show how to equip a sword, a shield, as well as a dual-wielding hammer (which forces to unequip the sword and the shield).


Not sure if this will help. I'll take a look nonetheless, but if you can provide some screenshots of a couple of items presenting this issue. Cheers!

+1

The Inventory examples contain some samples that show how to equip a sword, a shield, as well as a dual-wielding hammer (which forces to unequip the sword and the shield).

I've been able to reproduce the issue several times. Just make a new Inventory type(example Legs). Set it up as normal, equip the new leg item, save the game. Now load the last save, the Leg item will still be equipped in the UI inventory but it will not render on the character in game. The same thing happens when adding any new inventory types other than the default types.

Here are some armor pieces(compatible with the default character) to test the above.

drive.google.com/file/d/195ckKc7Knn4DtiU5ecZZz6KrAqV1RD4J/view?usp=sharing

+1

Nice spotting, Medafor!

That could explain the difference I'm seeing, though I haven't had time to test in my build yet. I know the Head slot works fine, but my Torso slot is the one in error (you can see the image of the inventory itself if you scroll up). I haven't had a chance to test more in the last couple of days.

I may actually even be building from a scene that originally contained the Inventory demo.

Jacob

+2

Thanks. I'll soon be updating the Inventory and I'll investigate this issue. Since it happens with the example scenes, it should be easy to reproduce. I'll circle back once I have more info on this. Thanks!