Unity-Technologies / com.unity.selection-groups

Other
117 stars 9 forks source link

Possible to consider adding the ability to query/add members from within SubScenes which are loaded for editing? #75

Closed MostHated closed 2 years ago

MostHated commented 2 years ago

Hey again, I didn't expect it to work, but I wanted to give it a try anyways. Of course, the result was that it didn't work, but I was wondering what the likelihood would be of supporting the ability to query/add members from within open SubScenes?

Ex.

Thanks, -MH

sindharta commented 2 years ago

We put in a small fix to address this, but perhaps the fix addressed a different issue, and we didn't fully understand the bug that you brought up. Could you please attach a small project that we can open to reproduce this ?

MostHated commented 2 years ago

Oh, sorry, it's not a bug I don't believe, more of a feature request. The items in the hierarchy (Section_1 - 4) are GameObjects within a subscene (each has a component on it of type SubSceneDetailsComponentAuthoring).

As it stands, queries don't seem to be able to access subscenes hierarchy to return those GameObjects, which I did not expect it to be able to, as in order to reference those objects myself now, I have to use something along the lines of this:

SubScene subScene;
...

if (!subScene.EditingScene.isLoaded) return;
var rootGameObjects = subScene.GetRootGameObjects();

for (int i = 0; i < rootGameObjects.Length; i++)
{
    // Do whatever
}

I was merely wondering if it were possible to extend the reach of the queries to be able to traverse the subscene hierarchy as well.

sindharta commented 2 years ago

Ah, silly me. For some reason, I thought this was related to a bug you brought up previously. Please give me some time to discuss this with the team.

smnwttbr commented 2 years ago

I believe if the selection group scope is set to 'Editor', it will be able to reference objects across all loaded scenes.

MostHated commented 2 years ago

I appreciate the reply. I will be sure to give this a try and report back.

MostHated commented 2 years ago

I can't seem to win, lol. I attempted to give this a go, and this was the result.

It seems to be only this window that has the issue, and it persists regardless of restarting the editor, resetting my layout, closing all other windows, etc. See below the image for the stack. I thought maybe it was due to having a pretty large number of groups at first (it was about an entire page full, so probably 30-35?), so I removed most of them and tried again with just the few that are seen here, but it didn't make a difference.

The first Error:

[Error] GUI Window tried to begin rendering while something else had not finished rendering! Either you have a recursive OnGUI rendering, or the previous OnGUI did not clean up properly.
Null Exception ```cs [Exception] NullReferenceException: Object reference not set to an instance of an object ContainerWindow.FindUnsavedChanges() at /home/bokken/buildslave/unity/build/Editor/Mono/ContainerWindow.cs:313 ContainerWindow.UnsavedStateChanged() at /home/bokken/buildslave/unity/build/Editor/Mono/ContainerWindow.cs:336 EditorWindow.CreateNewWindowForEditorWindow() at /home/bokken/buildslave/unity/build/Editor/Mono/EditorWindow.cs:1168 EditorWindow.Show() at /home/bokken/buildslave/unity/build/Editor/Mono/EditorWindow.cs:617 EditorWindow.Show() at /home/bokken/buildslave/unity/build/Editor/Mono/EditorWindow.cs:609 EditorWindow.GetWindowPrivate() at /home/bokken/buildslave/unity/build/Editor/Mono/EditorWindow.cs:661 EditorWindow.GetWindow() at /home/bokken/buildslave/unity/build/Editor/Mono/EditorWindow.cs:675 EditorWindow.GetWindow[T]() at /home/bokken/buildslave/unity/build/Editor/Mono/EditorWindow.cs:741 EditorWindow.GetWindow[T]() at /home/bokken/buildslave/unity/build/Editor/Mono/EditorWindow.cs:715 SelectionGroupConfigurationDialog.Open() at Library/PackageCache/com.unity.selection-groups@0.5.1-preview/Editor/SelectionGroupConfigurationDialog.cs:29 27: internal static void Open(ISelectionGroup group, SelectionGroupEditorWindow parentWindow) 28: { -->29: var dialog = EditorWindow.GetWindow(); 30: dialog.group = group; 31: dialog.parentWindow = parentWindow; SelectionGroupEditorWindow+<>c__DisplayClass17_0.b__2() at Library/PackageCache/com.unity.selection-groups@0.5.1-preview/Editor/SelectionGroupEditorWindow.GUI.cs:402 400: group.Clear(); 401: }); -->402: menu.AddItem(new GUIContent("Configure Group"), false, () => SelectionGroupConfigurationDialog.Open(group, this)); 403: if(!string.IsNullOrEmpty(group.Query)) 404: menu.AddItem(new GUIContent("Update Query Results"), false, () => SelectionGroupManager.ExecuteQuery(group)); GenericMenu.CatchMenu() at /home/bokken/buildslave/unity/build/Editor/Mono/GUI/GenericMenu.cs:127 ```
sindharta commented 2 years ago

@MostHated Is it possible for you to give us a sample project to reproduce this ? I tried what you showed in the screenshot, but I couldn't reproduce the error.

MostHated commented 2 years ago

I had been trying to remove anything excess that I had in my project just in case it had anything to do with something else in there.

I cleared out the library folder and reimported everything, I tried closing all windows and tabs except the main window, but nothing helped, it was still happening, so I will try and see if I can get something small together.

MostHated commented 2 years ago

Ok, with a brand new project in which I only added some of the packages I was currently using, I was able to repro it with none of my code in the project.

I can compress it up, where should I upload it? I can just put it on my Google drive and provide a link, if that works?

sindharta commented 2 years ago

Sounds great. You can use Google Drive, or you can just drag and drop it here when creating a comment.

MostHated commented 2 years ago

Oh, I didn't even realize you could upload actual files here. That said, I tried and it gave me an error.

So I just uploaded it here. I deleted the library contents, as it was over 2gb even though it was a new project due to being an hdrp project (I wanted to try and simulate my setup as much as I could). It's only 30mb now.

https://drive.google.com/file/d/1kAwrg8NWCys2Tx0m4YeXOq9Y_VZ-iBVt/view?usp=sharing

Here is exactly what I did to get the error with this exact project.

smnwttbr commented 2 years ago

I cannot replicate this using your project, however I will examine the stack trace and see if I can make a workaround.

MostHated commented 2 years ago

Not the best solution, but if I make the package a local and point to it via file:/ in the manifset and then modify SelectionGroupConfigurationDialog.cs as seen below, this does resolve the issue on my end.


        private static bool windowReady;
        internal static void Open(ISelectionGroup @group, SelectionGroupEditorWindow parentWindow)
        {
            var dialog = EditorWindow.GetWindow<SelectionGroupConfigurationDialog>();
            dialog.group = group;
            dialog.parentWindow = parentWindow;
            dialog.refreshQuery = true;
            dialog.titleContent.text = $"Configure {group.Name}";
            windowReady = true;
            dialog.ShowPopup();
            dialog.debugInformation = null;
        }

        private void OnEnable()
        {
            windowReady = false;
        }

        void OnGUI()
        {
            if (!windowReady) return;
            if (group == null)
            {
                Close();
                return;
            }
            // ...
        }

sindharta commented 2 years ago

Not the best solution, but if I make the package a local and point to it via file:/ in the manifset and then modify SelectionGroupConfigurationDialog.cs as seen below, this does resolve the issue on my end.

@MostHated Sorry for the delay. I also checked your project and I could not reproduce the error that you showed up there. It seems strange to me that OnGUI is called even when the window hasn't been opened Do you still have this error now ?

MostHated commented 2 years ago

I have just been using my modified version, I will have to test it out with a new default version and get back to you.

sindharta commented 2 years ago

Btw, SelectionGroups in version 0.5.5-preview can contain GameObject in subscenes. But if you unload the subscene, then it will be deleted.

sindharta commented 2 years ago

I believe we have resolved this issue, so I am going to close it. Please feel free to reopen it if necessary