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!

This commit is contained in:
yasirkula
2021-12-19 19:04:34 +03:00
parent f724dd2fdb
commit 9648f856d1
@@ -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<Transform>( 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