yasirkula / UnityAssetUsageDetector

Find usages of the selected asset(s) and/or Object(s) in your Unity project, i.e. list the objects that refer to them

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Searching for a Prefab doesn't always show results starting with Unity.GameObjects

TimmermanV opened this issue · comments

If I search for a Prefab and have 'Don't search "Find references of" themselves for references' unchecked, the results are not always as clear as I'd expect/hope/like. ;-)

For example, the orange marked object is actually in the scene as well, but doesn't show up as a result itself. (is this as expected?)
Example

However, when switching to "Shorter" view, the result doesn't start with the game object, but shows the prefab itself as the root. (if I click it, the prefab is selected in the project view) I would have expected to see the game object in the scene as first result.
image

If I enable 'Don't search "Find references of" themselves for references' the Shorter view does show the game object. However, the other game object that holds an indirect reference is not shown. (is this as expected?)
image

So my main issue is that in some cases, neither the Full, nor the Shorter view shows the Prefab instance as a search result.

Shorter path drawing mode shows only the last few nodes of each path and these paths always start with a UnityEngine.Object. It is the expected behaviour for Shadow to not appear in the last image, it should appear only in Full path drawing mode.

After a search is complete, AssetUsageDetector removes root nodes that are already a part of other nodes' paths, here is the code that does that:

// For simplicity's sake, get rid of root nodes that are already part of another node's hierarchy
for( int i = references.Count - 1; i >= 0; i-- )
{
if( IsRootNodePartOfAnotherRootNode( i, callStack ) )
references.RemoveAtFast( i );
}

This reduces the number of duplicate entries in search results. Feel free to uncomment it and see if it helps.

'Don't search "Find references of" themselves for references' is set to true by default since it can make the search results harder to interpret as you're experiencing. My recommendation is to set it to false only if you have multiple objects in "Find references of" list and you are interested in the references between these objects, as well.

neither the Full, nor the Shorter view

Here, you've meant "neither the Shorter, nor the Shortest view", right? Full path should show all references (as seen in the first picture).

P.S. About the second picture, I agree that it'd be better for search results of a scene to always start with a scene object in Shorter path drawing mode.

It was actually about "Splash" not appearing as a search result. (as a root node I guess) "Splash" is an instance of the Prefab I'm searching for, yet I only get indirect references through a different GameObject in the same scene. It's also missing from the Full view. I did mean neither Full nor Shorter, because Shorter does show "Splash" as a root node when I use 'Don't search "Find references of" themselves for references'.

It doesn't appear at the root of the Full view because of the code snippet I've shared, this is the expected behaviour.

You can see Splash at the root in Shorter view when 'Don't search "Find references of" themselves for references' is set to true because this is the Full path when that option is enabled:

ss

When we follow the path in reverse order, the first UnityEngine.Object we see is Splash GameObject. When 'Don't search "Find references of" themselves for references' is disabled, the first UnityEngine.Object we see is a NodeCanvas.BehaviourTrees.BehaviourTreeOwner component, hence why it is at the root of the Shorter view in your second screenshot. But as I said, I agree that it'd be better for search results of a scene to always start with a scene object in Shorter view; I'll try to implement this feature and keep this issue open until then.

Thanks for the explanation and for considering this feature. :-)