TylerTemp / SaintsField

A Unity Inspector extension tool focusing on script fields inspector enhancement
MIT License
184 stars 10 forks source link

Performace Improvement for Asset Searching Using `QuickSearch` #66

Open laurentopia opened 3 months ago

laurentopia commented 3 months ago

It could be a bug in unity 2020 where public MCFluid currentPrefab won't show prefab assets with MCFluid attached to it. I was trying my luck with FieldType, thinking that maybe you worked something around that bug. if it's not workable don't sweat it.

TylerTemp commented 3 months ago

public MCFluid currentPrefab won't list all prefab with MCFluid because, answered by Unity: "for performance consideration".

You can use

[FieldType(typeof(MCFluid))]  // or [FieldType(typeof(MCFluid), EPick.Assets)] if you need
public MCFluid currentPrefab;

This is what I did in my game project as a workaround.

Well, I indeed am considering [FieldType] with no type provided to search just the target type. But that's another story

TylerTemp commented 3 months ago

This feature has been added in 3.2.4

[FieldType]  // or [FieldType(EPick.Assets)] if you need
public MCFluid currentPrefab;
laurentopia commented 3 months ago

Here is what happens when I press the button with the dark disc image image image then this closes immediately when I don't click anywhere it eventually appears and shows the right elements, that's nice but now i understand "for performance consideration" ;) I thought that unity cached all types in the asset database... Anyway here is the deep profile, 100k IO woot! that would be harsh on a mechanical harddrive with too little cache. image

This is what I did in my game project as a workaround.

Which version of Unity do you use? with only 11k assets, getting such a slow read might be a regression in 2020.3.48

TylerTemp commented 3 months ago

I'm using 2022, but this is not likely an issue of version. The function internally will load every asset to search.

Well, Unity did add a thing called QuickSearch API which should make this situation much better. But I have never dig into it yet. And when I knew it, it was quite new and not backported to old Unity. Not sure how's the things today.

laurentopia commented 3 months ago

That's a good idea: quicksearch would reduce the search to prefab only, that's a few hundred objects down from 11k. looks to be a callback in 2020 and direct peek in 2022 don't you love hunting for API changes var results = SearchService.Request("t:prefab"); foreach (var result in results) { string path = AssetDatabase.GUIDToAssetPath(result.id); etc...

TylerTemp commented 3 months ago

don't you love hunting for API changes

Backward compatibility is still a consideration for this project, asiding with Unity's LTS list (oldest is 2019.4). It's possible to use marco to selectively run code, but that means we need to maintain 2 code logic, which we already have: UIToolkit + IMGUI. Adding more on it seems quite difficult considering the status of the project and the spare time we have (((

I'll keep this issue open and considering it when the time is proper.