Forum rules - please read before posting.

Action: Switch Scene +1

Is it possible to create an Action Scene/Switch next (the opposite of Scene/Switch previous)? I tried to modify the script, but my ignorance of C# is devastating.
Could someone help me with that?
Thank you,


  • edited November 2022

    To clarify: the "Switch previous" command refers to the last-visited scene - not the next scene up in Unity's build settings.

    But as for a custom Action, try this:

    using UnityEngine;
    using System.Collections.Generic;
    using UnityEditor;
    namespace AC
        public class ActionSceneNext : Action
            public bool assignScreenOverlay;
            public bool relativePosition = false;
            public Marker relativeMarker;
            protected Marker runtimeRelativeMarker;
            public int relativeMarkerID;
            public int relativeMarkerParameterID = -1;
            public bool forceReload = false;
            public override ActionCategory Category { get { return ActionCategory.Scene; }}
            public override string Title { get { return "Switch next"; }}
            public override string Description { get { return "Moves the Player to the next scene in the build settings."; }}
            public override int NumSockets { get { return (isAssetFile) ? 1 : 0; }}
            public override void AssignValues (List<ActionParameter> parameters)
                runtimeRelativeMarker = AssignFile <Marker> (parameters, relativeMarkerParameterID, relativeMarkerID, relativeMarker);
            public override float Run ()
                int currentSceneIndex = KickStarter.kickStarter.gameObject.scene.buildIndex;
                int runtimeSceneIndex = currentSceneIndex + 1;
                if (relativePosition && runtimeRelativeMarker != null)
                    KickStarter.sceneChanger.SetRelativePosition (runtimeRelativeMarker);
                KickStarter.sceneChanger.ChangeScene (runtimeSceneIndex, true, forceReload, assignScreenOverlay);
                return 0f;
            #if UNITY_EDITOR
            public override void ShowGUI (List<ActionParameter> parameters)
                forceReload = EditorGUILayout.ToggleLeft ("Reload even if scene is already open?", forceReload);
                relativePosition = EditorGUILayout.ToggleLeft ("Position Player relative to Marker?", relativePosition);
                if (relativePosition)
                    relativeMarkerParameterID = Action.ChooseParameterGUI ("Relative Marker:", parameters, relativeMarkerParameterID, ParameterType.GameObject);
                    if (relativeMarkerParameterID >= 0)
                        relativeMarkerID = 0;
                        relativeMarker = null;
                        relativeMarker = (Marker) EditorGUILayout.ObjectField ("Relative Marker:", relativeMarker, typeof(Marker), true);
                        relativeMarkerID = FieldToID (relativeMarker, relativeMarkerID);
                        relativeMarker = IDToField (relativeMarker, relativeMarkerID, false);
                assignScreenOverlay = EditorGUILayout.ToggleLeft ("Overlay current screen during switch?", assignScreenOverlay);
                if (isAssetFile)
                    EditorGUILayout.HelpBox ("To perform any Actions afterwards, 'Is skippable?' must be unchecked, and 'Survive scene changes?' must be checked, in the ActionList asset's properties.", MessageType.Info);
            public override void AssignConstantIDs (bool saveScriptsToo, bool fromAssetFile)
                AssignConstantID (relativeMarker, relativeMarkerID, relativeMarkerParameterID);
            public override bool ReferencesObjectOrID (GameObject gameObject, int id)
                if (relativePosition && relativeMarkerParameterID < 0)
                    if (relativeMarker && relativeMarker.gameObject == gameObject) return true;
                    if (relativeMarkerID == id && id != 0) return true;
                return base.ReferencesObjectOrID (gameObject, id);
            public override int GetNextOutputIndex ()
                if (NumSockets > 0)
                    return 0;
                return -1;
  • Thank you very much!
    Sorry to bother you again, but I tried placing it in several folders (inclusing a Custom Actions folder) and keep getting a message saying that the script "must derive fro AC's Action class in order to be available as an Action".
    Could you help me with this as well?
    Thank you

  • The AC debug logger:

    -> AC debug logger
    UnityEngine.Debug:LogError (object,UnityEngine.Object)
    AC.ACDebug:LogError (object,UnityEngine.Object) (at Assets/AdventureCreator/Scripts/Static/ACDebug.cs:46)
    AC.AdventureCreator:AddActionsFromFolder (AC.ActionsManager,string,System.Collections.Generic.List`1<AC.ActionType>) (at Assets/AdventureCreator/Scripts/Managers/Editor/AdventureCreator.cs:590)
    AC.AdventureCreator:RefreshActions () (at Assets/AdventureCreator/Scripts/Managers/Editor/AdventureCreator.cs:495)
    AC.AdventureCreator:OnEnable () (at Assets/AdventureCreator/Scripts/Managers/Editor/AdventureCreator.cs:39)

  • Check that the script's filename matches the class, i.e. ActionSceneNext.cs, and make that the scripts inside the folder it's placed in are exclusively Action scripts.

  • Naming as your example did the trick, thank you!

  • As stated in the previous comment, the error message has been solved. However, the action does not run :(
    I have tried with normal scene names ('start' and 'second') and naming with numbers ('1' and '2'). I have also tried creating another hotspot switching to the second scene by name and coming back to the first one, just in case.
    No error message, though: it identifies the area as a hotspot (or button), but it is as if no action had been specified.

  • Try running the ActionList its placed in manually, by clicking "Run now" in its Inspector.

    Are your scenes added to the build settings, and do any messages appear in the Console?

  • nope... :(
    I have a second hotspot and button going to the next scene by name and they work. No error message either.
    I placed a build here (B&W arrow uses the next scene name, button and white arrow use the next scene script) here in case you want to see it, but I suspect I should try to find alternatives.

  • I must apologise - it was a typo in the script.

    I've amended it above, please give it another go.

  • It works!
    No reason to apologize: you are the best!

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.