diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs index 80bd2b1..c13590b 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs @@ -861,6 +861,23 @@ namespace AssetUsageDetectorNamespace SearchVariablesWithSerializedObject( result ); } + // A prefab asset should have a link to its children because when a scene object uses a prefab and a child of that prefab uses + // a searched object, the scene object needs to appear in the search results. Since prefab assets aren't automatically linked to + // their children, we need to create that link manually + if( assetPath != null && unityObject is GameObject && AssetDatabase.IsMainAsset( unityObject ) ) + { + if( result == null ) + result = PopReferenceNode( unityObject ); + + GameObject prefabGameObject = (GameObject) unityObject; + Transform[] prefabChildren = prefabGameObject.GetComponentsInChildren( true ); + for( int i = 0; i < prefabChildren.Length; i++ ) + { + if( prefabChildren[i].gameObject != prefabGameObject ) + result.AddLinkTo( SearchObject( prefabChildren[i].gameObject ) ); + } + } + callStack.RemoveAt( callStack.Count - 1 ); } else