Class SceneFieldAttribute
Marks a string field so the Inspector renders it as a scene selection dropdown
populated from the project's Build Settings instead of a raw text input.
Inherited Members
Namespace: Scylla.Core.Attributes
Assembly: ScyllaCore.dll
Syntax
[AttributeUsage(AttributeTargets.Field)]
public sealed class SceneFieldAttribute : PropertyAttribute
Remarks
When this attribute is applied to a serialized string field, the custom
property drawer (SceneFieldDrawer) replaces the default text field with a
popup listing every enabled scene registered in the Build Settings window.
The scene's filename (without the .unity extension) is stored in the
backing field, making it directly usable with SceneManager.LoadScene and
related Unity scene-loading APIs.
Using this attribute instead of a raw string field provides several benefits:
- Eliminates typos: the designer selects from a curated list rather than typing a scene name by hand.
-
Simplifies refactoring: when a scene is renamed, the Inspector will
flag the stale reference with a
(Missing)suffix, making it easy to spot broken links at edit time rather than at runtime. - The dropdown is rebuild-cached: it only re-queries Build Settings when the scene list actually changes, so rendering remains efficient even with large projects.
Field type requirement: The decorated field must be of type string.
If the attribute is placed on any other type, the Inspector will display a red
error help box and the field will not be editable until the type is corrected.
Missing scene handling: If the stored scene name is not currently present
among the enabled Build Settings scenes (for example, after the scene was removed
from the build or renamed), the drawer prepends a (Missing) entry at the
top of the dropdown. The stored value is preserved so that re-adding the scene to
Build Settings restores the correct selection without data loss.
Disabled scenes: Only scenes with their checkbox enabled in the Build Settings window appear in the dropdown. Disabled scenes are intentionally excluded to avoid referencing content that will not ship.
Empty Build Settings: If no scenes are enabled in Build Settings, the Inspector will display a yellow warning help box instead of the dropdown, prompting the developer to add at least one scene to the build.
public class LevelManager : MonoBehaviour
{
/* Dropdown showing all enabled scenes from Build Settings. */
[SceneField]
[SerializeField] private string _mainMenuScene;
[SceneField]
[SerializeField] private string _gameplayScene;
public void LoadMainMenu()
{
SceneManager.LoadScene(_mainMenuScene);
}
public void LoadGameplay()
{
SceneManager.LoadSceneAsync(_gameplayScene);
}
}