regression: in debug mode the inspector no longer allows to swap script (IN-14760)

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.
8388342--1106508--Screen Shot 2022-08-24 at 5.57.16 PM.png

4 Likes

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)
8388564--1106568--upload_2022-8-24_22-0-19.png
boom one click and now we have another hull generator
8388564--1106571--upload_2022-8-24_22-1-51.png

and in 2021.3.8 it still worked so this regression is fairly recent.
8398218--1108680--Screen Shot 2022-08-28 at 9.22.03 PM.png

1 Like

[quote=“laurentlavigne”, post:4, topic: 892146]
and in 2021.3.8 it still worked so this regression is fairly recent.

[/quote]
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 :).

3 Likes

[quote=“oscarAbraham”, post:5, topic: 892146]
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.
[/quote]
Interesting insight! Regressions are top priority at Unity so I’m sure they’ll fix that soon.

[quote=“oscarAbraham”, post:5, topic: 892146]
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?
[/quote]

https://unity3d.atlassian.net/servicedesk/customer/portal/2/IN-14760

[quote=“laurentlavigne”, post:6, topic: 892146]
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
[/quote]

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:
https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-14069

3 Likes

[quote=“laurentlavigne”, post:8, topic: 892146]
It’s been reproduced by their team and is now being worked on.
Here is the public link:
https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-14069
[/quote]
It says “The page you were looking for doesn’t exist.” :confused:

[quote=“oscarAbraham”, post:9, topic: 892146]
It says “The page you were looking for doesn’t exist.” :confused:
[/quote]
It’s live now, and the regression is still in b9.

1 Like

regression is still there in b16!!

8623158--1158420--upload_2022-11-29_11-47-12.png

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

2 Likes

Shame, there has been no news or updates on this, even after 6 months. Really frustrated.

[quote=“castor76”, post:12, topic: 892146]
Shame, there has been no news or updates on this, even after 6 months. Really frustrated.
[/quote]
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!

1 Like

[quote=“castor76”, post:14, topic: 892146]
Oh my hopefully the option still exists in 2023.1 if so, it is a life saver! Thanks!
[/quote]
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 :stuck_out_tongue:

Edit: The option still exists (and it still works to enable Script reference changes) in 2023.1.0b2.

1 Like

I got an email on this case, they're working on a fix.

1 Like

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();
    }
}
3 Likes

Unfortunately, it seems like work around using
8831584--1202605--upload_2023-2-24_12-21-27.png

for Unity 2023.1.b5 isn't working anymore... :(

Bumping this as a reminder!