A very useful feature of Unity that existed since the dawn of time got axed in 2022. Probably an oversight.
See how the script bucket is grayed out, can’t swap script no more.
I’ve been meaning to bring this up as well, was indeed a great feature I’ve had occasion to miss a few times already.
Here is how it used to be (and why I reverted back to 2020.x)
boom one click and now we have another hull generator
and in 2021.3.8 it still worked so this regression is fairly recent.
In 2022.2, they are using UI Toolkit to generate the Debug Inspector. That must be it.
The script field needs to be implemented differently from other ObjectFields because it can’t update every time you select something in the Object Picker. It needs to way until the definitive selection is made because the inspected Object reloads every time a script is assigned. So they would need to do a new implementation of the ObjectField to support this. I really hope they forgot to implement it instead of just deciding it’s not worth it.
This is such a life saving feature in a lot of scenarios. If they send you an issue-tracker link, would you mind sharing it so we can track it and vote for it?
Thank you :).
Interesting insight! Regressions are top priority at Unity so I’m sure they’ll fix that soon.
https://unity3d.atlassian.net/servicedesk/customer/portal/2/IN-14760
That’s good to hear! I don’t have a lot of experience tracking bugs. A couple of experiences have led me to think that sometimes they need user attention to be taken care of; if you say regressions are a top priority, I believe you and I feel a lot better about it. Thank you.
It seems only the user that reported it can access the bug report with this new system, unlike the old FogBugz one. It says that I don’t have permission to view it. I guess that’s good in the long run. Thank you again.
It’s been reproduced by their team and is now being worked on.
Here is the public link:
It says “The page you were looking for doesn’t exist.”
It’s live now, and the regression is still in b9.
regression is still there in b16!!
and it’s been 4 month since posted so a fix for release doesn’t look hopeful
listen, guys, if you don’t want to fix this regression, at least make a blog post so that you confront your decision
and also to give us devs a warning not to use this version during proto phase
Shame, there has been no news or updates on this, even after 6 months. Really frustrated.
At least there’s a workaround:
https://forum.unity.com/threads/2022-2-eta-on-fixing-the-inspector-inspector-debug-mode-regression-uum-14069.1372317/#post-8668128
Oh my hopefully the option still exists in 2023.1 if so, it is a life saver! Thanks!
I can confirm it is still available and working in 2022.2.5f1 …I’m installing the latest 2023 shortly, so I’ll edit this post once I’ve checked, but probably you’ll know before I do
Edit: The option still exists (and it still works to enable Script reference changes) in 2023.1.0b2.
I got an email on this case, they’re working on a fix.
Just hit this in 2022.2 as well. While waiting for Unity to fix this, I made this context menu command as a workaround:
using System.IO;
using UnityEditor;
using UnityEngine;
/// <summary>
/// Command to change the script a MonoBehaviour instance is using.
/// </summary>
/// <remarks>
/// In old Unity versions, this could be done easily, since the script
/// field was enabled and allowed to directly change it.
/// Later Unity disabled the field but it was still editable in
/// the debug inspector as a workaround.
/// In Unity 2022.2 the field in the debug inspector was disabled as
/// well, making it impossible in the UI to change scripts.
///
/// Apparently this is a regression and might be fixed at some point?
/// https://issuetracker.unity3d.com/issues/cannot-change-scripts-in-inspector-window-when-in-debug-mode
///
/// This class adds a command in all MonoBehaviour context menus,
/// opening a file picker to choose a script to replace it with.
///
/// One current limitation is that scripts from non-embedded packages
/// cannot be chosen, this would have to be detected specifically
/// and the path adapted accordingly to make it work.
/// </remarks>
public static class ChangeScriptCommand
{
[MenuItem("CONTEXT/MonoBehaviour/Change Script...")]
static void ContextMenu(MenuCommand command)
{
if (!(command.context is MonoBehaviour instance))
return;
// Path to project Assets folder
var assetsPath = Application.dataPath;
var scriptPath = EditorUtility.OpenFilePanel(
$"Select script to replace '{instance.GetType().Name}' with",
Application.dataPath,
"cs"
);
if (string.IsNullOrEmpty(scriptPath))
return;
// Turn path into a project-relative one, required for AssetDatabase
var projectPath = Path.GetDirectoryName(assetsPath);
var relativePath = Path.GetRelativePath(projectPath, scriptPath);
var script = AssetDatabase.LoadAssetAtPath<MonoScript>(relativePath);
if (script == null) {
EditorUtility.DisplayDialog(
"Could not load script",
"No MonoScript found at path:\n" + relativePath,
"OK"
);
return;
}
ChangeScript(instance, script);
}
public static void ChangeScript(MonoBehaviour instance, MonoScript script)
{
var so = new SerializedObject(instance);
var scriptProperty = so.FindProperty("m_Script");
scriptProperty.objectReferenceValue = script;
so.ApplyModifiedProperties();
}
}
Unfortunately, it seems like work around using
for Unity 2023.1.b5 isn’t working anymore…
Bumping this as a reminder!