Forum rules - please read before posting.

"Global Container" Script

Is it possible to have more than one Global Container?

Also, the wiki instructions state that the container and Don'tDestroyMe component should be placed in the game's first scene. My game's first scene is the Main Menu though, so no real gameplay. Does it matter if the container is in here, wouldn't it affect how items in the container are saved and loaded, since the game: reset action reverts to this scene?

Comments

  • The wiki script is just a helper - it can be amended if necessary. All it does, however, is cause an object to survive scene changes.

    There's no limitation on how many Containers you can add to it - just add each as a new child object, with its own Remember Container.

    The only important thing is that the root object itself appears in the "DontDestroyOnLoad" scene in the Hierarchy window at runtime (which is what the script does). When AC saves the game, any Remember component placed in this scene will be treated as "global" data.

    The "first scene" the wiki page describes shouldn't be visited again. If you use this technique, create a new first scene that simply has this prefab, and switches to your main menu scene on startup.

    Alternatively, you can attach the Containers to e.g. your Player prefab, provided they are used across all scenes (and not overridden with a local Player in any scenes).

  • Forgive me if I'm being dumb here, but how can I open this container when testing in the editor? As in, how can I actually select that container to open in the Container: Open action, if that container is not present in the scene in which I am play testing?
    Does the container that is placed in the first scene need to be made a prefab and placed into all scenes?

  • If you're using the "startup scene" method, you'd need to temporarily place a copy of the Container prefab into the scene you want to test - or otherwise find a way to begin testing from the startup scene.

    For example, your startup scene could have an OnStart cutscene that converts a "Debug Scene Load" integer variable into an Integer ActionList parameter that's then fed into the Scene: Switch Action.

    Alternatively, attaching Container(s) to your spawned Player prefab will avoid the need for this.

  • "you'd need to temporarily place a copy of the Container prefab into the scene you want to test"
    Would it cause problems if I just left it in there? It's just that, if I delete it, the Container:open action now displays nothing - not even a constant ID (even though the container itself definitely has one).

    I understand how the data is saved, I just don't get how to have the actionlist open the container if it's not in the scene. I have it in the scene to test, but if you're supposed to delete it after testing, then how is the actionlist able to retain reference to it?

    btw I cannot use the player prefab method as I rely on players already present in the scene.

  • edited September 2023

    So long as the Actions reference the original Container prefab, they should record/rely on the Constant ID value.

    I'm forgetting myself re: spawning it at runtime, however. As of 1.78, there's an easier way to automate this by using the Events Editor.

    Create a new Scene: Change: After Event, and have this run the Object: Check presence Action that detects the prefab. If the prefab isn't presence, spawn it in with Object: Add or remove.

    The prefab should still have the "DontDestroyMe" component attached, so that it only gets spawned once, but it should then get spawned no matter which scene you begin from.

  • Hmm, I cannot get it to work using the original method. It works if the container is in the scene, but I'm guessing that's potentially problematic. I noticed though, during runtime the container is not included under the DontDestroyOnLoad object in the Hierarchy window, despite it having the Don't Destroy Me script.

    btw I cannot use the new events method as unfortunately this project (which is nearly done) is locked in on Unity 2018.4.3 which I believe is (understandably) no longer supported by the latest AC versions.

  • Ah, okay so the containers weren't being included in DontDestroyOnLoad because they were children of the Logic/Container object in the Hierarchy. Removing them from that and leaving them as their own / root objects seems to have solved it.
    I will test more with loading saves, loading between scenes etc.

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.