Forum rules - please read before posting.

Non-linear gameplay and replaying a scene

Hello,
this might be a though one. In our game, there's gonna be a scene that represents the central Hub of the game, from where you can check your progress and replay one of the memories you've already unlocked. The hub is also the only place in which you can save the game (for simplicity).

Now, my problem: in some scenes there might be something optional (for example, a collectible) that needs to be tracked in the player progress and shown in the Hub, and this might lead to a player needing to replay one memory from scratch. I've tried with "Engine:End - reset scene" action, but to no avail. How can I restore a scene to its initial state, let the player play it again from the start, and track any additional "loot" that he/she might obtain in this rerun? Because, for what I got lurking in the forum searching for answers, I don't think that saving the initial state of the memory and reloading might help me here..

As usual, I'm using Unity 2020.2.0f and AC v. 1.72.4

Regards,
Willy

Comments

  • Is each "memory" its own scene, or a series of scenes?

    The "Reset Scene" command will clear all data specific to the open scene - i.e. Remember component data, which NavMesh is active, etc.

    Through scripting it is possible to clear the data of scenes that aren't currently open, but this data is not related to anything "global", such as the Player's inventory, or Global Variable values.

    What data exactly are you looking to reset/clear when a memory is replayed?

  • Hi Chris,
    for the time being yes, each "memory" has its own single scene (and we can take it as a constraint from now on, if it solves our problem with replaying them).

    The "Reset Scene" command will clear all data specific to the open scene - i.e. Remember component data, which NavMesh is active, etc.

    I've tried switching to the target scene and immediately call the "Reset Scene" action after the loading has completed, but it didn't work. If it should work, and there's only a problem on my side, it's ok, we can fix it and then I can add some actions to restore the inventory intended state at the start of that memory. Basically, the inventory is usable only during a memory, and since memories aren't necessarily connected, there's no risk of messing it up between scenes.

    What data exactly are you looking to reset/clear when a memory is replayed?

    Well, I'd like to reset every local variable, hotspot visibility and interactions that are present in the scene as if it's the first time it's loaded. For example: during my memory I have 4 hotspots initially visible, and after interacting with all four a fifth one is unlocked and has a starting "Talk To" dialogue. This dialogue changes after the first time, and so forth. With my previous test, if I replay the memory all five hotspots are visible, the dialogue is the second one et cetera et cetera.

    Hope this helps!

    Willy

  • Resetting the scene should result in the scene data being cleared, and then the scene reloaded. Which aspect of this isn't working?

    Rather than resetting things when you first start the scene, try resetting it before switching to it. Through script, this can be done with:

    AC.KickStarter.levelStorage.ClearLevelData (2);
    

    (where "2" is the name of the scene's build index)

    As a test, try placing this code in a new C# script and place in your hub scene:

    [ContextMenu ("Clear data")]
    void ClearDataTest ()
    {
        AC.KickStarter.levelStorage.ClearLevelData (2);
    }
    

    In it's Inspector at runtime, click its context menu (the cog at the top-right of the component) and choose "Clear data", before opening the scene without resetting it in OnStart. Does that restore things to their original state as intended?

  • Hi Chris,

    Resetting the scene should result in the scene data being cleared, and then the scene reloaded. Which aspect of this isn't working?

    Apparently the data isn't being cleared, but I'll try with your code and let you know as soon as possible.

    Willy

  • Thank you Chris,
    it works! I've realized that there's a lot of small tinkering that needs to be done on the objectives side (not only the inventory), but this is a HUGE step in the development. Thank you very much!

    Willy

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.