Forum rules - please read before posting.

Empty inventory at once, reset certain scenes variables

Is there anyway to easily and quickly remove all items from inventory without having to remove each one via separate action lists?

Plus, a quick and easy way to set a scene's variables back to original settings rather than when ending game?

Comments

  • Is there anyway to easily and quickly remove all items from inventory without having to remove each one via separate action lists?

    All items can be removed from the Inventory by calling:

    AC.KickStarter.runtimeInventory.RemoveAll ();
    

    As usual for running custom code, place inside a public C# function and use the Object: Call event Action to trigger the function via a GameObject or prefab its attached to.

    Plus, a quick and easy way to set a scene's variables back to original settings rather than when ending game?

    The Engine: End game Action has a Reset Scene option, which will reset all saved data associated with the scene. This'll include both local variables, as well as custom Remember data.

    To reset only the variables, define a preset in the Variables Manager to set up values to revert to, and use the Variable: Assign preset Action to assign them.

  • To reset only the variables, define a preset in the Variables Manager to set up values to revert to, and use the Variable: Assign preset Action to assign them.

    What about local variables (which is the majority of variables I need to reset)

    The Engine: End game Action has a Reset Scene option, which will reset all saved data associated with the scene. This'll include both local variables, as well as custom Remember data.

    I need to reset all the variables and remember data from a number of scenes, local and global variables. Would be good to have a scene Reset Scene option not just for end game.

  • edited February 2022

    What about local variables (which is the majority of variables I need to reset)

    Presets are available for Local variables.

    Would be good to have a scene Reset Scene option not just for end game.

    Reset Scene will do nothing other than reset the scene data for the active scene - you don't need to use it when your game is ending.

    If you want to reset the data for a specific scene, you can call the LevelStorage class's ClearLevelData function:

    AC.KickStarter.levelStorage.ClearLevelData ("MyScene");
    
  • edited February 2022

    ok thanks.

    And it regards to:

    use the Object: Call event Action to trigger the function via a GameObject or prefab its attached to.

    I have a prefab in every scene that has the attached script, as I need to call this through an action list out of scene (dropping item on main player causes death, which needs to therefore empty inventory and reset all variables in certain scenes) - and I cannot currently drop the scene script prefab into the inventory object on to prefab player in play.

  • A prefab used only to store a script function you want to call does not need to be in the scene. The Object: Call event Action can reference the prefab asset directly.

  • So I have had some help to create this custom action:

    using UnityEngine;
    using System.Collections.Generic;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionClearLevelData : Action
        {
    
            // Declare properties here
            public override ActionCategory Category { get { return ActionCategory.Scene; }}
            public override string Title { get { return "Clear Level Data"; }}
            public override string Description { get { return "Wipes stored data for a specific scene from memory."; }}
    
    
            // Declare variables here
            public ChooseSceneBy chooseSceneBy = ChooseSceneBy.Name;
            public string sceneName;
            public int sceneNameParameterID = -1;
            public int sceneNumber;
            public int sceneNumberParameterID = -1;
    
            public override void AssignValues (List<ActionParameter> parameters)
            {
                sceneNumber = AssignInteger (parameters, sceneNumberParameterID, sceneNumber);
                sceneName = AssignString (parameters, sceneNameParameterID, sceneName);
            }
    
    
            public override float Run ()
            {
                switch (chooseSceneBy)
                {
                    case ChooseSceneBy.Number:
                        if (sceneNumber < 0) return 0f;
    
                        AC.KickStarter.levelStorage.ClearLevelData (sceneNumber);
                        break;
    
                    case ChooseSceneBy.Name:
                        if (string.IsNullOrEmpty (sceneName)) return 0f;
    
                        AC.KickStarter.levelStorage.ClearLevelData (sceneName);
                        break;
                }
    
                return 0f;
            }
    
    
            public override void Skip ()
            {
                /*
                 * This function is called when the Action is skipped, as a
                 * result of the player invoking the "EndCutscene" input.
                 * 
                 * It should perform the instructions of the Action instantly -
                 * regardless of whether or not the Action itself has been run
                 * normally yet.  If this method is left blank, then skipping
                 * the Action will have no effect.  If this method is removed,
                 * or if the Run() method call is left below, then skipping the
                 * Action will cause it to run itself as normal.
                 */
    
                 Run ();
            }
    
    
            #if UNITY_EDITOR
    
            public override void ShowGUI (List<ActionParameter> parameters)
            {
                chooseSceneBy = (ChooseSceneBy) EditorGUILayout.EnumPopup ("Choose scene by:", chooseSceneBy);
    
                if (chooseSceneBy == ChooseSceneBy.Name)
                {
                    sceneNameParameterID = Action.ChooseParameterGUI ("Scene name:", parameters, sceneNameParameterID, ParameterType.String);
                    if (sceneNameParameterID < 0)
                    {
                        sceneName = (string) EditorGUILayout.TextField("Scene name:", sceneName);
                    }
                }
    
                if (chooseSceneBy == ChooseSceneBy.Number)
                {
                    sceneNumberParameterID = Action.ChooseParameterGUI ("Scene number:", parameters, sceneNumberParameterID, ParameterType.Integer);
                    sceneNumber = (int) EditorGUILayout.IntField ("Scene number:", sceneNumber);
                }
            }
    
    
            public override string SetLabel ()
            {
                // (Optional) Return a string used to describe the specific action's job.
    
                return "Wipes stored data for a specific scene from memory.";
            }
    
            #endif
    
        }
    
    }
    

    This only works on scenes that are not the current scene. I need the current active scene resetted too but all attempts to do so thus far have failed.

    Are you able to help?

  • If you want to reset the current scene, you can use the regular Engine: End game Action.

  • edited February 2022

    But i don't want to end the game, just to restart player at a specific scene and reset certain scenes? Won't restart game put player at the beginning of the game again?

    On a certain 'death' I want to empty inventory (i now have a custom action) and reset certain scenes as player will be reborn in scene 3, not scene 1, and i need scenes 3, 4, 5, 6 reset

  • The Action's Reset Scene method will only do just that - it won't do anything else.

  • Thanks, but it seems that my script above won’t reset current scene. So if I was to ‘die’ in the scene that you restart in after death (not end game) then that scene will not reset. Anyway to tweak the above script to ensure that happens?

  • Right i got it nowe, thanks!

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.