Forum rules - please read before posting.

Loading save games with Unity UI menu prefabs

edited July 2021 in Technical Q&A

Hello!

Some details first: Using AC 1.73.8, and Unity 2021.1.7f1, and all menus are Unity UI.

In the game, there's two "map open" menu icons (each with button components) in the top-right corner, which have Appear Type: Manual.

Clicking the icons opens a different map / menu:

  • A mobile phone "open icon" appears at the game's beginning and in most other parts of the game to open a map on a mobile.
  • In some places if the mobile phone doesn't get service, a paper map is needed -- so a paper / physical map "open icon" sometimes appears in that same top-right corner.

Here's a screenshot of the two icons / menus:
https://imgur.com/a/WDzHqmz

Have used Menu: Turn On and Menu: Turn Off to control when they're supposed to show, and It all works well in normal game playthroughs.

The phone icon appears first in the game. After the paper map has been picked up, the phone icon turns off with Menu: Turn Off, and the paper map turns on with Menu: Turn On.
Immediately after this and loading a game that was saved before picking up the paper map, both icons appear and overlap like this:
https://imgur.com/a/s6fwW47

My understanding was that when a save file is loaded, menus just reset to the state they were in when the save was made -- which was mentioned in this thread.

Are there any thoughts on solving this?

A potential reason why it could be happening is because the paper map is still activated under the objects marked as "DontDestroyOnLoad".
Here's a screenshot showing the Paper map icon ("MapIslandOpenButton") activated in the DontDestroyOnLoad objects, right after it is picked up, and the Phone map icon ("MapOpenButton") deactivated -- as they both should be.
https://imgur.com/a/OpQSX9m

And here's a screenshot showing the Paper map icon ("MapIslandOpenButton") activated in the DontDestroyOnLoad objects right after the save game is loaded -- as it should not be since it wasn't picked up yet (in terms of order of game events, not technically speaking):
https://imgur.com/a/lvFrCSj

If DontDestroyOnLoad is related to the issue, trying to better understand: how does AC mark / classify objects as DontDestroyOnLoad? Understandably, DontDestroyOnLoad is part of Unity, though is it possible to "unmark" an object as DontDestroyOnLoad using AC?

-

Also, tried another other semi-unrelated thing to solve this issue -- though it didn't appear to have any effect:
In the "Load" menu (in the saved games list element), I created and assigned an "ActionList after loading", with a Variable: check that turns on / off the appropriate map icons.

Thank you very much for any assistance!

Comments

  • If DontDestroyOnLoad is related to the issue, trying to better understand: how does AC mark / classify objects as DontDestroyOnLoad?

    AC will flag Unity UI prefab menus as this automatically, as they should survive scene changes. Their location in the Hieararchy shouldn't be a factor, however.

    As Unity UI is another layer of complexity, though, it'll be necessary to know if this is isolated to Unity UI menus only. Temporarily switch these two menus back to Adventure Creator as their Source. Don't worry about restyling them too much - we just need to see if the issue still occurs when not using Unity UI.

    In the "Load" menu (in the saved games list element), I created and assigned an "ActionList after loading", with a Variable: check that turns on / off the appropriate map icons.

    If this had no effect, it sounds like the Menus are being forced back on after the loading process. As a test to confirm this, update your "ActionList after loading" asset with just Menu: Change state Actions to turn off the Menus regardless of any variable. Do they still appear?

    If so, place this script in the scene you're saving in and loading from:

    https://pasteall.org/zQ3w#L3

    That will make a log entry in the Console whenever a Menu is turned on. Look for the one that mentions the Menu in question - what is the message in full?

    Another approach to this situation would be to change the Appear type to something else, e.g. During Gameplay, and then turn it on/off by unlocking/locking it instead. This'll automate the turn on/off operation, and the Menu's "locked" state will be stored in save game files.

  • edited July 2021

    Thank you for that!

    Opted to go with changing the Appear Type to During Gameplay, as it was straightforward and already essentially set up with the logic for that -- just needed to change all the exiting "Turn On" and "Turn Off" actions for the menus to "Unlock" and "Lock" actions respectively. It appears to work fine this way.

    Was under the impression that the menu states would be stored in save game files with "Menu: Turn On / Off", as well.
    Is one of the differences between "Turn Off" and "Lock Off", that "Turn Off" is considered to fully disable a menu, and not retain menu states to be stored in save game files (like "Lock On / Off")?

    In any case, good to know for future reference.
    Thank you for the assistance!

  • There are some caveats made internally (such as if a Menu contains a SavesList element), but generally the enabled state of a Menu should be saved just as its locked state is.

    The above script will help to understand what the issue was, if you'd like to help look into this further. It'd also be worth using the Save-file Manager (available from the Settings Manager) to view the raw data created by the save file in question - specifically, the "Menu Visibility Data" section.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.