Forum rules - please read before posting.

Does AC.LocalVariables.GetVariable not work inside the Start(){} function?

edited September 2022 in Technical Q&A

I have a separate custom script that triggers some interactivity based on whether a local variable has been triggered. It checks in the 'Start() {}' function, and it was returning false every time, even when the editor showed the variable as true. Just to test if it was maybe a race condition, I used a coroutine and yield waitforseconds to wait 1 second before checking that worked. So is it not possible to properly use the AC.LocalVariables.GetVariable function on Start()?

(I figured this second part out already, you can add a script called 'remember hotspot', and it remembers disabling your hotspot, easy!!)
I have an interaction/cutscene that will disable a hotspot for a particular scene, and after it gets disabled, I want it to stay disabled for the rest of the game in that area. I do set a local variable that gets triggered from this cutscene, so currently I have an actionlist that gets triggered on this scene's start, that will check that variable and if true, disable the hotspot manually at the start every time. But is there a better way? Like an option when disabling a hotspot that just saves the disabled state permanently after that point in-game?

Comments

  • edited September 2022

    What's your AC version, and under what conditions is the scene starting? Beginning the game, switching from another, or loading a save file?

    The cleanest approach to run custom code as the scene begins is to hook into the OnAfterChangeScene custom event, which fires once the scene begins regardless of the starting condition:

    private void OnEnable () { AC.EventManager.OnAfterChangeScene += OnChangeScene; }
    private void OnDisable () { AC.EventManager.OnAfterChangeScene -= OnChangeScene; }
    
    private void OnChangeScene (AC.LoadingGame loadingGame)
    {
        // Start code here
    }
    

    For more on custom events, see this tutorial.

  • That worked perfectly, thank you so much for your help!

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.