Skip to content

InspectorUtil fails to load current Inspector window in Unity 2018 #30

@Maclay74

Description

@Maclay74

So, it looks like something is broken in 2018.3 beta.

Everything is working great in Editor, but when you try to Play, initialize error occurs.
Seems like, something goes wrong in Initialize function in Assets\OneLine\OneLine\Editor\Utils\InspectorUtil.cs

So, in order to work around I found useful to check is s_CurrentInspectorWindow really exist and in case of null return false.

So, there are some changes I've made:

       public InspectorUtil() {
            enabled = false;
            if (EditorWindow.focusedWindow is PopupWindow) return; // Detect is it [Expandable] popup

            try {
                if (this.Initialize()) // Additional check
                    enabled = true;
            }
            catch (Exception ex){
                Debug.LogError(INITIALIZATION_ERROR_MESSAGE + ex.ToString());
            }
        }

       private bool Initialize(){
            inspectorWindowType = Type.GetType(INSPECTOR_WINDOW_ASSEMBLY_QUALIFIED_NAME);

            // If this field doesn't exist, return false
            if (inspectorWindowType.GetField("s_CurrentInspectorWindow") != null) {
                window = inspectorWindowType
                .GetField("s_CurrentInspectorWindow", BindingFlags.Public | BindingFlags.Static)
                .GetValue(null);    
            } else {
                return false;
            }
            
            scrollPositionInfo = inspectorWindowType.GetField("m_ScrollPosition");
            getWindowPositionInfo = inspectorWindowType.GetProperty("position", typeof(Rect))
                                                        .GetGetMethod();

            var test = ScrollPosition;
            return true;
        }

I see that new version is coming, hope this issue would be helpful.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions