EditorWindow.minSize not working if docked.

I have recently upgraded from 2020 LTS to 2021.2.17f1.
I have some custom EditorWindows which I like to keep docked. Now in 2021 the minSize seems to be ignored IF they are docked. If the windows is free floating it adheres to the set minSize.

Here you can see it in action:
First I have the window floating and it’s very small (as I want it).
As soon as I dock it it can not be resized to a smaller vertical size (it pushes the other window down).
8003273--1029260--EditorWindowMinSize.gif

The code used is very simple:

    [MenuItem("Window/BreakOnClick")]
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        var window = (BreakOnClick)EditorWindow.GetWindow(typeof(BreakOnClick));
        window.minSize = new Vector2(22, 22);
        window.Show();
    }

I tried to remove all code in OnGUI() just to make sure there is not “layouting” stuff breaking anything. But still, the result is the same.

Any workaround for this?

Did you try the Reset Layouts (upper right)? It could be the window layout properties are in some weird borked state after the upgrade.

If you can get this behavior in a new empty project, I say file a bug.

Good idea!
… Sadly it does not change the behaviour :-/
I think I’ll have to investigate a little more.

1 Like

Sniff around the window API (or is it EditorWindow I guess??) because maybe they changed it to have another property, like “safe size” or something else that must also be set nowadays… Just random thoughts to try.

Haha, yes, maybe I’ll have to unwrap my reflections club to hit Unity with it :smile:. Yes, it’s an EditorWindow. I have found some older posts about docked editor windows not adhering to maxSize. So maybe this is an old issue which now also affects minSize in 2021. It’s not a high priority thing for me though. Just a little annoying.
Thanks.

Hi!
Have you found a solution to this issue, by chance? I have the same problem, and it’s quite annoying.
It seems to not be a bug, but is as design, as the documentation of EditorWindow.minSize has been updated and now say “The minimum size is not used when the window is docked.”
But… in this case, I guess we have another way of setting min size for docked windows. Else, it’s pure regression. Anyone know what would be this way?

Sorry, I have not yet investigated this in detail. No solution thus far.

1 Like

Also interested

+1

Min-size for docked windows is defined in an internal class:

1 Like

Buy why :frowning:

I added the following script to the “Editor” folder of my Unity project to work around the problem.

It is working fine in my environment.

using System.Reflection;
using UnityEditor;
using UnityEngine;

namespace Kogane.Internal
{
    [InitializeOnLoad]
    internal static class SetDockedMinSize
    {
        static SetDockedMinSize()
        {
            // https://github.com/Unity-Technologies/UnityCsReference/blob/bf25390e5c79172c3d3e9a6b755680679e1dbd50/Editor/Mono/HostView.cs#L94
            var type      = typeof( Editor ).Assembly.GetType( "UnityEditor.HostView" );
            var fieldInfo = type.GetField( "k_DockedMinSize", BindingFlags.Static | BindingFlags.NonPublic );

            fieldInfo!.SetValue( null, new Vector2( 100, 44 ) );
        }
    }
}

8790157--1194364--image.gif

10 Likes

Thank you so much!
I’m still pretty mad at Unity team to have randomly break the initial feature, but your fix is a lifesaver!

You just saved my life