Field in Inspector to point to a Scene to load.

I would like to set up a field in the inspector where the user can drag a Unity Scene from the Project tab.

Not having much luck.

I cannot find what this Asset field type should be and fromt he forum I am gathering that there isn’t one available. Is this still the case?.

If it is the case. I was thinking that I could extend the the editor somehow in such a way that the user could drag the Scene asset, then the editor would convert the asset to the assetpath as text and store that.

It seems like it would work except that the user cannot drag the object into the box because the box is a text field. :frowning:
Can I override the drop behaviour of the inspector field so it will accept whatever type I tell it to?

Or is there a better solution for this.

Thanks

I’m trying to do that as well. I found this on the forum but haven’t tried it yet.

http://answers.unity3d.com/questions/242794/inspector-field-for-scene-asset.html

I’ll let you know if I have any luck.

2 Likes

I found this via Google and I have provided a simple solution to the answer post linked above if anyone else finds this too.

3 Likes

Here’s a simple solution that I just found that worked for my game. I attached this “scene loader” script to an object with a collider on it. This lets you drag a scene from your project files into the inspector. You can rename the scene in your project folder, and it still works with no additional tweaking :slight_smile:


[SerializeField] Object scene;

private void OnTriggerEnter(Collider other) {
if (other.CompareTag(“Player”)){
SceneManager.LoadScene(scene.name);
}
}


4 Likes

This is actually really smart! It worked for me perfectly. good job :slight_smile:

This works well in the editor, but stops working in a build.

1 Like

You may use this asset: