Scene variables on Don'tDestroyOnLoad "scene"

I am saving scene variables from an object marked as “Don’tDestroyOnLoad”, this is creating a new visual scripting scene variable’s instance. Now I am trying to get these variables but SceneVariables.Instance just receives a Scene asset as parameter. I already searched on all the current active scenes and none of them have the variables.

How can I access to these variables? Someone on internet said Visual Scripting creates a new “scene” called “Don’tDestroyOnLoad” but, as I mentioned before, SceneVariables.Instance just receives a scene asset and this “new scene” doesn’t actually exists, so I can’t gather info for that mysterious scene

it creates a new Game Object in the hierarchy called don’t destroy on load not a scene right?
8491436--1129736--Capture1.PNG
anyways this is the node you use to get saved variables:

8491436--1129733--Capture.PNG

Thanks for the answer, but notice I specified a different processes, like pass a scene asset as parameter, hence I am talking about get this variables from code. Sory whether I was not clear enough. Anyway, thanks again!.

ah, sorry.
didn’t realize you’re looking how to access the variables via script

Example script to set ActiveScene variable.

using Unity.VisualScripting;
using UnityEngine;

public class setsceneVariable : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Variables.ActiveScene.Set("MySceneText", "test");
    }
}

You can find documentation about it at: Variables node | Visual Scripting | 1.7.8 (unity3d.com)

Scene variables are living in a GameObject named “VisualScripting SceneVariables” and are automatically added the first time a visualscript graph is added to a scene in the same scene as the GameObject. Having multiple scenes loaded additively, won’t make let you see scenes variables from other scenes.
8492138--1129904--upload_2022-10-5_15-14-13.png

1 Like

Yeah I saw that Doc and this doesn’t have the answer.
And sure, you can’t access to variables for another scenes, but I am talking about DontDestroyOnLoad “scene”. I put “” because that is not a real scene. I am adding a scene variable from jerbaroo(Clone) object. How can I access to those variables?. I already checked all scene variables from all active scenes and they are not anywhere.

8494139--1130345--upload_2022-10-6_10-20-16.png

Scene Variables are scene specific - each scene has one such object. It shouldn’t be marked as DontDestroyOnLoad. Use Application variables for scene independent variable tracking.

Hey, thanks for the reply. I am not marking this as DontDestroyOnLoad, it has been created automatically there. So here is the question. If there is not a scene present, why has this been created at all?
I used application as workaround, thanks for the suggestion.
This should throws an error when you try to create a scene variable from a DontDestroyOnLoad object.

I wonder if it could be destroyed after load? :stuck_out_tongue:

are you sure the values you are trying to access are not just the Visual scripting scene variables?
those do exist before run time. like a normal var


Note the Scene tab here this is where those vars are stored ^

Weird indeed. Maybe a bug. My understanding is that Scene variables are or at least were in Bolt a scene scope singleton. Once a new scene is loaded additively, its Scene Variables overrides the previous scene variables as the current tracked reference. And they are destroyed on non-additive scene load.

I always thought of scene variables as like just a pre-named object variable container. basically holds values like if you just made an emptyobject and attached object variables kinda thing.

but for some reason it instantiates itself and changes the name so the user doesn’t delete it on accident. otherwise it would have the same name? i dono

it’s clearly addin’ somthin’ as child objects ^.^
8491436--1129736--Capture1.PNG

It essentially is that - a GameObject containing Variables component that’s automatically created by UVS in every scene that has ScriptMachine or StateMachine component somewhere in Hierarchy.

The few ways it’s different from Object variables is that UVS references this scene variables GO automatically and Get/Set Scene Variable nodes don’t have GameObject targets because the system only references one instance of Scene Variables. Whenever a new scene is loaded additively with its own Scene Variables GO, the system internally then references the newly loaded Scene Variables because it expects only one Scene Variables instance to exist i.e. a scene scope singleton of sorts if you will.

1 Like

neato’
always interesting stuff to talk about.

why doesn’t it just create an asset file in the project folder to store this game object?
surely it could be generated at runtime from an external file
just wondering why the need to spam the hierarchy even if you never use any scene variables?

i imagine it’s built like this because bolt. how it was like added-on
and also, the canvas has that eventsystem but the canvas is a whole other topic too lol