Forum rules - please read before posting.

Local variables and add/remove scene

In my first person 2D point and click, there is a building with various rooms and hallways. Each room or section of the building is its own scene, because it would be much too large to have all the building interior as one scene.

Initially, I used scene:switch to move between these interior scenes, but since the scene switches were at points where the screen wouldn't pause and fade to black, it was causing noticeable jankiness as the player moved through. For example, there was a heavy blur on the screen during switches, and if the player kept clicking during the switch there would be a black flash and they would teleport too far ahead on the load in.

I tried a lot of work-arounds (loading asyncronously, preventing clicking during switches, etc.) but I still wasn't happy with the result, so I changed to an add/remove setup. With this, I made a parent scene for the entire building, and then added and removed rooms as the player passed through.

This worked PERFECTLY and fixed all my problems, but now all of the local variables for each room are not accessible and everything that references them is not working. Is there any way I can keep this add/remove setup and still access local variables? Or do I need to do a big rework and remake the local variables in the parent scene?

I personally don't know code, but I have others on the project who do - so a code solution would also be welcome.

Thank you so much for the help!


  • You'll want to be sure to have a backup on hand, but there's a couple of ways forward.

    One is to rely on Component variables instead of Local. Component variables are attached to GameObjects - though they can still be accessed by others, as well as from asset files.

    This is generally best practice when a Variable is related to a specific object, i.e. a "Locked" state for a Door.

    You'd need to convert such Variables manually, so it'd depend on how many you have - but you can get AC to list references to your Local variables via the cog icon beside each in the Variables Manager. This'll print a list in the Console of any Action that it finds in the scene that references a particular Variable - which you can use to help find which Actions need changing.

    The other option would be to rely on sub-scenes, rather than spawning in each scene as a prefab. The Scene: Add or remove Action can be used for this - though bear in mind that because you can't "move" a scene, you'd need to ensure that each scene's background is positioned uniquely, so that they don't overlap.

    The advantage of using sub-scenes over prefab spawning is that scene-based Variable Actions will refer to the Local variables in the scene that they are run in.

  • Thank you for the response, Chris! It appears that the issue is actually specifically related to custom scripts that reference local variables, but there aren't many so I can find work-arounds.

    Also component variables sound useful in general - I should start using those

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.