Forum rules - please read before posting.

Enable/Disable Hotspot in other scene

Hello,
Is it possible to change hotspot in other scene?
example
Picked an item in Scene1 (added to inv, disabled hotspot, disabled visibility), went to Scene2 doing some action lost my item and item is supposed to went back to place in Scene1 and be active?

I want to make it this way:

  • store information about hotspot and item taken in Scene1 in object1 that will RememberData (coz without it, would lost this information Save/Load)
  • In Scene 2 change the data in object1 according to item lost
  • onLoad the Scene1 check if object1 has some data about Hotspot and visibility status in this Scene, then apply any change needed.

Is this good way or you have other that is Built in AC

Comments

  • It's possible to access the data of other scenes, but it'd be very complicated to manipulate - you'd need to deserialize it, amend it, re-serialize, and then update.

    One other way would be to place the Hotspot in both scenes, and make sure both of them have the same Constant ID number. You can then attach a script to transfer data from the previous scene with objects that share the same ID:

    using UnityEngine;
    using AC;
    
    public class TransferRememberData : MonoBehaviour
    {
    
        private Remember[] remembers;
    
        private void OnEnable ()
        {
            remembers = GetComponents<Remember>();
            EventManager.OnAfterChangeScene += OnAfterChangeScene;
        }
    
        private void OnDisable ()
        {
            EventManager.OnAfterChangeScene -= OnAfterChangeScene;
        }
    
        private void OnAfterChangeScene (LoadingGame loadingGame)
        {
            if (loadingGame == LoadingGame.No || loadingGame == LoadingGame.JustSwitchingPlayer)
            {
                SceneInfo previousSceneInfo = KickStarter.sceneChanger.GetPreviousSceneInfo (false);
    
                foreach (SingleLevelData levelData in KickStarter.levelStorage.allLevelData)
                {
                    if (levelData.sceneNumber == previousSceneInfo.number)
                    {
                        foreach (ScriptData _scriptData in levelData.allScriptData)
                        {
                            if (_scriptData.data != null && _scriptData.data.Length > 0)
                            {
                                foreach (Remember remember in remembers)
                                {
                                    if (_scriptData.objectID == remember.constantID)
                                    {
                                        remember.LoadData (_scriptData.data);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    
    }
    

    It's recommended, however, to instead rely on Variables to do this. For example, a Global Boolean named "Item is in scene A", that you set to False when picked up, and True if the item is lost in scene B. Scene A's OnLoad/OnStart cutscenes would then read this variable's value and enable/disable the Hotspot accordingly.

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.