From 9648f856d19bf7ab5fe2325c70097b71d3a7b5a4 Mon Sep 17 00:00:00 2001 From: yasirkula Date: Sun, 19 Dec 2021 19:04:34 +0300 Subject: [PATCH] When a scene object had a reference to a prefab and one of that prefab's children used a searched asset (e.g. a sprite), that reference couldn't be found (it's surprising how this bug couldn't be detected for so long). Fixed! --- .../Editor/AssetUsageDetector.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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