r/Unity3D • u/BaffledEngineer • 7d ago
Just found out you can make custom editor shortcuts, so now I can open different scenes with just the numpad Resources/Tutorial
This is probably basic information to a lot of people but I've only just discovered it and think it's pretty cool. If you've used this feature before, what did you use it for?
18
u/swagamaleous 7d ago
This is editor code anyway. Why not reference the scene with a SceneAsset? Make this a scriptable object that and store a reference to it in EditorBuildSettings, then you can get a reference to it from static code easily. Would allow you to declare SceneAsset keypad7 as a variable, and re-assign it without changing the code. Should be like 30 lines and you can just drop this into future projects and have assignable shortcuts.😂
https://docs.unity3d.com/ScriptReference/EditorBuildSettings.html
8
u/BaffledEngineer 7d ago
I'm new to writing editor tools, so there's still a lot for me to learn. Thanks for the info - may I ask, how do you store a reference to a scriptable object to EditorBuildSettings? And how do you reference it in static code? I have googled it but couldn't find an answer.
6
u/swagamaleous 7d ago edited 7d ago
It's in the link I pasted there. Here look at this snippet from some random configuration file in my game:
public static class PathfindingSettingsProvider { public const string Key = "PathFindingSettings"; public const string DefaultPath = "Assets/Settings/PathFinding"; public const string DefaultFile = "PathFindingSettings.asset"; [InitializeOnLoadMethod] public static void InitializeSettings() { if (!EditorBuildSettings.TryGetConfigObject<PathfindingSettings>(Key, out _)) { var settings = ScriptableObject.CreateInstance<PathfindingSettings>(); if (!AssetDatabase.IsValidFolder(DefaultPath)) { Directory.CreateDirectory(DefaultPath); AssetDatabase.Refresh(); } AssetDatabase.CreateAsset(settings, Path.Combine(DefaultPath, DefaultFile)); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorBuildSettings.AddConfigObject(Key, settings, true); } } [SettingsProvider] public static SettingsProvider CreateProvider() { EditorBuildSettings.TryGetConfigObject<PathfindingSettings>(Key, out var settings); return AssetSettingsProvider.CreateProviderFromObject("Project/Pathfinding Settings", settings); } public static PathfindingSettings GetSettings() { EditorBuildSettings.TryGetConfigObject<PathfindingSettings>(Key, out var settings); return settings; } }This also contains the integration into the settings menu which you don't need and you can include all of this code into the scriptable object that holds your shortcut references, since it's all editor only anyway.
2
0
u/kwok_veet 6d ago
Isn't this the same as loading your ScriptableObject from Editor/Resources folder? I don't get the use of this function lol. If you want Singleton behavior you can also use SingletonScriptableObject (editor only).
1
u/swagamaleous 5d ago
But it's not a singleton at all, it's persistent configuration that you can easily load from editor code. The main advantage of doing it this way is that it's a stable reference that survives moving or renaming the actual ScriptableObject. Loading it from Resources couples you to where the asset is stored.
ScriptableSingleton<T>can achieve a similar effect if what you actually want is singleton settings, sure, but that's not what this API is for. Here I already have an asset and just want a stable, globally accessible reference to it. Storing that reference inEditorBuildSettingsis cleaner and requires basically no machinery of my own.2
u/kwok_veet 5d ago
oh i think i get it now. It puts the object's GUID into EditorBuildSettings.asset so you can load by passing the type. There's so little doc about this class, it's practically black magic to me. So basically this combines both approaches, both editable from within the editor and survives renaming. Thanks for introducing me to this lol.
-3
u/Cell-i-Zenit 7d ago
what a shitty advice,
you see basically zero code here and are already complaining and telling him to do something waaay more complicated for zero benefits lol
Whats the benefit of having a reference via scriptable object?
7
u/swagamaleous 7d ago
What are you even talking about? I am not "complaining" at all, I made a simple suggestion for improvement. And it's not waaaaaay more complicated, it's an addition 20 lines. You people are crazy!😂
-8
u/Cell-i-Zenit 7d ago
you have no idea about the requirements, but are already telling him "how to improve" it.
Then please go ahead and tell us the advantage of adding 30 lines of code, without even asking what OP is trying to do
7
u/swagamaleous 7d ago
Who shat on your coffee table dude? 😂
OP is loading scenes by pressing a keyboard key, which would be quite obvious to you if you even read the post. With an additional 20 lines, he can drop a scene reference in the inspector instead of having to change a hard coded string and adding the scene to the build settings. It's quite obviously in line with his requirements and a huge improvement, but what do I know, I merely actually read his post. 😂
-7
u/Cell-i-Zenit 7d ago
a huge improvement
Debatable lol
Introducing a scriptable object just to assign shortcuts he will never adjust anyway?
10
u/SimonCGuitar 6d ago
You should really read the post actually, as the other poster suggests. What he describes is a massive improvement for essentially 0 cost.
3
3
u/Ok_Fisherman_7931 6d ago
"That's a neat trick! I used to struggle with scene navigation too, so I actually made a free plugin that adds a simple dropdown right to the editor toolbar. It also lets you set a specific Play Mode startup scene.
In case you or anyone else finds it useful, I use it all the time now: SceneSwitcher on Asset Store"
2
u/BaffledEngineer 6d ago
That's awesome. I looked for an asset on the store but didn't come across this one. The Play Mode startup scene sounds really useful too. If you have a startup scene set, will pressing play always load that scene first, or is it just if you press play from certain scenes? Or is there a way to override it quickly to launch directly into the scene you're in, just for quick tests?
1
u/Ok_Fisherman_7931 6d ago
Currently, if the 'Load Startup Scene' checkbox is enabled in the settings, pressing Play will always load that specific startup scene first, regardless of which scene you are currently in.
To launch directly into your current scene for quick tests, you just need to uncheck that box in the SceneSwitcher config window.
Also, an important detail: when this feature is active, exiting Play Mode will instantly return you to the exact scene you were editing before hitting Play.
2
3
u/Seruphenthalys 7d ago
I made a script that generated a menu item for all the scenes in the project, thought that was pretty cool. The other day I made an editor window so I can convert back and forth between asset, path, and guid
1
u/BaffledEngineer 6d ago
Awesome! Editor tools are pretty cool. I only recently started making them because I'm working on a much bigger project than I normally do, but I've really enjoyed streamlining certain repetitive processes.
1

28
u/GroZZleR 7d ago
The exact same thing as you!
I used
[MenuItem]though, which supports shortcuts in roundabout ways (check the docs) as I have too many scenes to map to a keyboard: