Forum rules - please read before posting.

Actions on leaving scene

I'm trying to execute some actions when leaving a scene, specifically deleting inventory items. My character is gathering various chemicals and pieces of equipment in a laboratory, which he can then combine to form a new item. However, when he leaves the laboratory with the original items still in his possession, I would like to delete them from the inventory. Leaving entails selecting a universal "Back" button that switches the camera, or a "Map" button that brings up a menu from where different scenes can be loaded.

Is there a way to tie inventory items to a certain scene and/or camera view? Alternatively, what is the best way to delete items (or running any actions) when changing a scene?

Thanks

Comments

  • I've found a workaround by preventing the player from leaving the laboratory until the task is completed, which then automatically removes the items and switches cameras. However, I would still be interested to know whether it is possible to link inventory items to a scene, or run an actionlist when changing scenes.

  • You can hook into the OnBeforeChangeScene custom event, fired just before the switch, to run an ActionList that handles the necessary inventory changes.

    Here's an example, ActionListBeforeChangeScene.cs, that you can use by placing on a new GameObject in the scene:

    using UnityEngine;
    using AC;
    
    public class ActionListBeforeChangeScene : MonoBehaviour
    {
    
        public ActionList actionListOnChangeScene;
    
        private void OnEnable () { EventManager.OnBeforeChangeScene += OnBeforeChangeScene; }
        private void OnDisable () { EventManager.OnBeforeChangeScene -= OnBeforeChangeScene; }
    
        private void OnBeforeChangeScene (string nextSceneName)
        {
            actionListOnChangeScene.Interact ();
        }
    
    }
    
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.