Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot favorite prefabs #36

Closed
hsandt opened this issue Oct 1, 2022 · 7 comments
Closed

Cannot favorite prefabs #36

hsandt opened this issue Oct 1, 2022 · 7 comments

Comments

@hsandt
Copy link

hsandt commented Oct 1, 2022

I cannot add prefabs to favorites. Both the Favorite Item menu item and drag-and-drop to Favorites stop working. Nothing happens when I do them. I removed some entries in case I was reaching some max limit, but it didn't help.

Debugging code FavoriteElements > CanBeFavorite shows that when dealing with a game object, the test go.scene == null always fails, because scene is a struct (although debug prints scene as "null (null)").

To be exact, I miraculously managed to add a prefab to the favorites, but at that moment I wasn't debugging CanBeFavorite, so I have no idea how I managed to do it (maybe the first time you drag-and-drop, scene is really considered null by the engine for some reason, although I don't see how it's possible from C#'s PoV; or maybe the check was exceptionally skipped for some reason).

The check should probably be replaced with another way to detect invalid scenes, e.g. !go.scene.IsValid(), or alternatively directly check if the game object is an asset with AssetDatabase.Contains(go).

@acoppes
Copy link
Owner

acoppes commented Oct 2, 2022

Interesting, I have to take a look, I must admit I can add prefabs without problems to the favorites but I believe I am adding them through the history window icon and not by drag and drop to the favorites window.

Will check it later but if you have some alternative and want to make a pull request, I can check and test that and if it works merge it.

Thanks for reporting the issue

@acoppes
Copy link
Owner

acoppes commented Oct 2, 2022

drag_prefab_favs

@acoppes
Copy link
Owner

acoppes commented Oct 2, 2022

Which version of unity, os, etc, are you on?

@hsandt
Copy link
Author

hsandt commented Oct 9, 2022

So I found how to cause the "miracle", which is what you are doing in the GIF: you must have a non-game object asset selected, then directly drag and drop the prefab, without selecting it first. This will exploit a bug in FavoriteElements(Object[] references), which checks favorites.CanBeFavorite(Selection.activeObject) instead of favorites.CanBeFavorite(reference). Therefore, the selection is unrelated to the drag-and-drop target, and you pass the check.

You can even do this with right-click > Favorite Item but it's trickier: right-click auto-selects the target. So you need to select a non-prefab asset first, then Ctrl+Right Click to additionally select the prefab you want to favorite and also open the contextual menu, then Favorite Item. Selection.activeObject only checks the first selection, so this will also check the non-prefab, which has no scene and can be added as favorite. You must then remove the non-prefab asset you selected from the favorites...

But that's all exploits that explain why it inconsistently worked. This should of course be fixed by replacing Selection.activeObject with reference, but then we will truly be unable to add prefabs to Favorites. So this must be combined with the fix mentioned in my first post to be complete.

P.S.: I'm using Unity 2022.1.10f1 on Ubuntu, but I suspect that with my new explanations, it is not relevant anymore.

@acoppes
Copy link
Owner

acoppes commented Oct 9, 2022

Awesome finding, will take a look, thanks for all the info.

@acoppes acoppes closed this as completed in 5890000 Oct 9, 2022
@acoppes
Copy link
Owner

acoppes commented Oct 9, 2022

@hsandt I changed to check if object is an asset now, and tested with different cases, can't be sure if it is a complete fix, don't have a lot of time to spend testing it, take a look if it works and will upload a new version later today.

acoppes added a commit that referenced this issue Oct 9, 2022
Changed to check reference object parameter instead of always Selection.object and also changed to check if object is an asset instead of scene == null, and should work since favorites window can only favorite assets.
@hsandt
Copy link
Author

hsandt commented Nov 16, 2022

I tested v1.1.8, and it's working fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants