Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in '2022.2 Beta' started by laurentlavigne, Aug 25, 2022.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    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.
    Screen Shot 2022-08-24 at 5.57.16 PM.png
     
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,549
    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.
     
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    Here is how it used to be (and why I reverted back to 2020.x)
    upload_2022-8-24_22-0-19.png
    boom one click and now we have another hull generator
    upload_2022-8-24_22-1-51.png
     
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    and in 2021.3.8 it still worked so this regression is fairly recent.
    Screen Shot 2022-08-28 at 9.22.03 PM.png
     
    Last edited: Aug 29, 2022
    adamgolden likes this.
  5. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    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 :).
     
  6. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    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
     
  7. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    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.
     
  8. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
  9. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
  10. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    It's live now, and the regression is still in b9.
     
    Last edited: Oct 1, 2022
    oscarAbraham likes this.
  11. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    regression is still there in b16!!

    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
     
    andreiagmu and oscarAbraham like this.
  12. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Shame, there has been no news or updates on this, even after 6 months. Really frustrated.
     
  13. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,549
  14. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Oh my hopefully the option still exists in 2023.1 if so, it is a life saver! Thanks!
     
    adamgolden likes this.
  15. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,549
    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 :p

    Edit: The option still exists (and it still works to enable Script reference changes) in 2023.1.0b2.
     
    Last edited: Feb 9, 2023
    castor76 likes this.
  16. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    I got an email on this case, they're working on a fix.
     
    adamgolden likes this.
  17. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,061
    Just hit this in 2022.2 as well. While waiting for Unity to fix this, I made this context menu command as a workaround:
    Code (CSharp):
    1. using System.IO;
    2. using UnityEditor;
    3. using UnityEngine;
    4.  
    5. /// <summary>
    6. /// Command to change the script a MonoBehaviour instance is using.
    7. /// </summary>
    8. /// <remarks>
    9. /// In old Unity versions, this could be done easily, since the script
    10. /// field was enabled and allowed to directly change it.
    11. /// Later Unity disabled the field but it was still editable in
    12. /// the debug inspector as a workaround.
    13. /// In Unity 2022.2 the field in the debug inspector was disabled as
    14. /// well, making it impossible in the UI to change scripts.
    15. ///
    16. /// Apparently this is a regression and might be fixed at some point?
    17. /// https://issuetracker.unity3d.com/issues/cannot-change-scripts-in-inspector-window-when-in-debug-mode
    18. ///
    19. /// This class adds a command in all MonoBehaviour context menus,
    20. /// opening a file picker to choose a script to replace it with.
    21. ///
    22. /// One current limitation is that scripts from non-embedded packages
    23. /// cannot be chosen, this would have to be detected specifically
    24. /// and the path adapted accordingly to make it work.
    25. /// </remarks>
    26. public static class ChangeScriptCommand
    27. {
    28.     [MenuItem("CONTEXT/MonoBehaviour/Change Script...")]
    29.     static void ContextMenu(MenuCommand command)
    30.     {
    31.         if (!(command.context is MonoBehaviour instance))
    32.             return;
    33.  
    34.         // Path to project Assets folder
    35.         var assetsPath = Application.dataPath;
    36.  
    37.         var scriptPath = EditorUtility.OpenFilePanel(
    38.             $"Select script to replace '{instance.GetType().Name}' with",
    39.             Application.dataPath,
    40.             "cs"
    41.         );
    42.         if (string.IsNullOrEmpty(scriptPath))
    43.             return;
    44.  
    45.         // Turn path into a project-relative one, required for AssetDatabase
    46.         var projectPath = Path.GetDirectoryName(assetsPath);
    47.         var relativePath = Path.GetRelativePath(projectPath, scriptPath);
    48.  
    49.         var script = AssetDatabase.LoadAssetAtPath<MonoScript>(relativePath);
    50.         if (script == null) {
    51.             EditorUtility.DisplayDialog(
    52.                 "Could not load script",
    53.                 "No MonoScript found at path:\n" + relativePath,
    54.                 "OK"
    55.             );
    56.             return;
    57.         }
    58.  
    59.         ChangeScript(instance, script);
    60.     }
    61.  
    62.     public static void ChangeScript(MonoBehaviour instance, MonoScript script)
    63.     {
    64.         var so = new SerializedObject(instance);
    65.         var scriptProperty = so.FindProperty("m_Script");
    66.         scriptProperty.objectReferenceValue = script;
    67.         so.ApplyModifiedProperties();
    68.     }
    69. }
    70.  
     
  18. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Unfortunately, it seems like work around using
    upload_2023-2-24_12-20-37.png

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

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    402
    Bumping this as a reminder!