Forum rules - please read before posting.

Saving the Last Camera for later Switching

edited June 2020 in Technical Q&A

For my Point & Click Game, I'm trying to make it so Right Click Camera Switches to the previous Camera/location in the Action List. Unfortunately, I'm not sure how to do this.

In a previous project, I got around it by making an Action List Input go back to the one main overview camera, but that isn't an option this time. Due to the many places the player can go, it needs to be the last camera. It's tedious to program this individual to every action list and when I tried, it actually caused problems.

I'd like to write a script that saves the last camera the player had switched to before the previous one and then find a way to call it back that LastCamera Variable/Parameter with an Action List. However, I'm having issues coding with AC Variables and attempts to use the Parameters or Variables proved unsuccessful. Saving the Last Camera so I can call it in an Action List would be an easy way to automate the process of Switching back. Could I get some Advice on how best to do this?


  • I'm not sure you'd have to resort to custom scripting - the Camera: Switch Action has a Return to last gameplay? option that can be used to return to the last camera used during gameplay. If clicked again once gameplay is resumed, it'll switch back to the original gameplay camera.

    If you do need/want to rely on scripting, AC stores the previous gameplay camera automatically in the GetLastGameplayCamera function. It can be accessed with:

    AC.KickStarter.mainCamera.GetLastGameplayCamera ();
  • edited June 2020

    Interesting. I was having issues with the Return to last Gameplay function when I was testing it earlier and I didn't see it in your manual, so I assumed that wasn't what it did and stopped using it. Just tried it again with an Action Input I setup earlier and it seems to work well now for some reason... Thanks! However, it brings me to another issue.

    Throughout many interactions, I of course have to turn certain Hotspots off either because they aren't important yet or because I don't want it conflicting with other hotspots Many of my action lists handle which Hotspots to turn on and off.

    Problem is that Returning to the last camera via the Action Input doesn't turn on or off the desired Hotspots. For example, if I click and move to one area, I'll usually turn its hotspot off. If I move to that area and then use that Return To Last Gameplay function to go back to the previous camera, the Hotspot that I disabled won't re-enable and now I won't be able to get back there. Can't find anyway to do this automatically with the Action Input or Action List. Is there anyway to get around this and automate control of the hotspots through the camera switch?

  • How are you running the Actions that turn on/off the Hotspots? Via a Trigger?

    You could try running such an ActionList after switching the camera with an ActionList: Run Action. A Trigger can be run manually in this way, even if the Player didn't come into contact with it.

    If you're inclined to rely on scripting, it's also possible to hook into the OnSwitchCamera custom event to run an ActionList whenever a particular camera is switched to:

    using UnityEngine;
    using AC;
    public class RunActionListOnSwitchCamera : MonoBehaviour
        public ActionList actionList;
        private void OnEnable () { EventManager.OnSwitchCamera += SwitchCamera; }
        private void OnDisable () { EventManager.OnSwitchCamera -= SwitchCamera; }
        private void SwitchCamera (_Camera old, _Camera newCamera, float tt)
            if (newCamera == GetComponent <_Camera>())
                actionList.Interact ();

    Also know that a Hotspot can be limited to by camera in its Inspector, so if you have a Hotspot that only needs to be active for one camera (or a selection), you can avoid having to manually turn it on/off.

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.