Skip to content

Commit 8a6fe82

Browse files
committed
Materials instantiated (cloned) at runtime are now searched correctly
1 parent c9ceab6 commit 8a6fe82

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,23 @@ private ReferenceNode SearchMaterial( Object unityObject )
571571
referenceNode.RemoveLink( i );
572572
}
573573

574+
// At runtime, Textures assigned to clone materials can't be searched with reflection, search them manually here
575+
if( searchTextureReferences && isInPlayMode && !AssetDatabase.Contains( material ) )
576+
{
577+
Shader shader = material.shader;
578+
int shaderPropertyCount = ShaderUtil.GetPropertyCount( shader );
579+
for( int i = 0; i < shaderPropertyCount; i++ )
580+
{
581+
if( ShaderUtil.GetPropertyType( shader, i ) == ShaderUtil.ShaderPropertyType.TexEnv )
582+
{
583+
string propertyName = ShaderUtil.GetPropertyName( shader, i );
584+
Texture assignedTexture = material.GetTexture( propertyName );
585+
if( objectsToSearchSet.Contains( assignedTexture ) )
586+
referenceNode.AddLinkTo( GetReferenceNode( assignedTexture ), "Shader property: " + propertyName );
587+
}
588+
}
589+
}
590+
574591
return referenceNode;
575592
}
576593

0 commit comments

Comments
 (0)