How to assign scene as a variable in the editor?

I’m working on a dialogue based game like much of Detroit become human or I guess doki doki literature club where at the end of each scene of dialogue there is a decision and depending on the decision you make it loads a new scene. I mean scene both as a scene component in unity and in the sense of like a movie scene or a scene in a book. I have a script that manages the dialogue decision and (in theory) loads the next scene. I’d like to be able to, in the editor, assign multiple scenes to an array in this script so I can reference them in the script in order to load the correct next scene. I’m not sure if this is a well known feature or if I’m just stumbling on it, but it turns out you maybe can’t do this? rather than, like would be typical, having slots in the array in the editor that you can drag and drop objects or whatever into, it just has “Element 0” with no option to add anything there. Is there a workaround for this? It’s really important I find a way to do this because I need the game to be pretty much modular so I can put anything where it needs to be as it grows.

Scene assets are an editor only construct. At compile time they get crunched down into something else, hence why we can’t reference then. Not to mention if we could, it would mean that the scene asset would be loaded into memory. So, probably a good thing that we can’t.

But it so happens that the docs for SceneAsset shows an example of how you might reference a scene: Unity - Scripting API: SceneAsset

Tons of other examples exist out there.

You could also use Addressables which does allow you to reference scenes via an AssetReference and load them asynchronously.

Mind you I would always encapsulate whatever my scene reference solution was in some kind of scriptable object, and just reference the scriptable object whenever I wanted to use a ‘scene’. That way you can also encapsulate any relevant data about said scene in the object too. This is always my approach, alongside using addressables.

Awesome, I think this is a good jumping off point to finding a solution.

I use this, it’s quite good. GitHub - JohannesMP/unity-scene-reference: A SceneReference wrapper class that uses ISerializationCallbackReceiver and a custom PropertyDrawer to provide safe, user-friendly scene references in scripts.

Eflatun is working on a more robust version, linked in Johannes’ readme, but as of this writing I wouldn’t recommend it yet.

interesting, I’ll look into it

I have been using Johannes’ scene reference for a few years. It is brilliant!!

EDIT: Thx @ I got this wrong: But you can now use SceneAsset.

SceneAsset is editor only.