Skip to content

Commit

Permalink
Fixed exceptions while searching for some URP assets' references due …
Browse files Browse the repository at this point in the history
…to their overriden GetHashCode functions
  • Loading branch information
yasirkula committed Mar 18, 2023
1 parent 3fa3344 commit d57a707
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public SearchResult Run( Parameters searchParameters )

// Initialize the nodes of searched asset(s)
foreach( Object obj in objectsToSearchSet )
searchedUnityObjects.Add( obj.GetHashCode(), PopReferenceNode( obj ) );
searchedUnityObjects.Add( obj.GetInstanceID(), PopReferenceNode( obj ) );

// Progressbar values
int searchProgress = 0;
Expand Down Expand Up @@ -672,7 +672,7 @@ private void CalculateUnusedObjects( List<SearchResultGroup> searchResult, out H
else
{
for( Transform parent = ( (GameObject) obj ).transform.parent; parent != null; parent = parent.parent )
usedObjectPathsSet.Add( parent.gameObject.GetHashCode().ToString() );
usedObjectPathsSet.Add( parent.gameObject.GetInstanceID().ToString() );
}
}
}
Expand Down Expand Up @@ -739,13 +739,13 @@ private void CalculateUnusedObjects( List<SearchResultGroup> searchResult, out H
if( !searchedTopmostGameObject )
{
if( obj is GameObject )
unusedMainObjectNodes[obj.GetHashCode().ToString()] = node;
unusedMainObjectNodes[obj.GetInstanceID().ToString()] = node;
else
currentSearchResultGroup.AddReference( node );
}
else // List child GameObject scene objects under their parent GameObject
{
string dictionaryKey = searchedTopmostGameObject.GetHashCode().ToString();
string dictionaryKey = searchedTopmostGameObject.GetInstanceID().ToString();
List<ReferenceNode> unusedSubObjectNodesAtPath;
if( !unusedSubObjectNodes.TryGetValue( dictionaryKey, out unusedSubObjectNodesAtPath ) )
unusedSubObjectNodes[dictionaryKey] = unusedSubObjectNodesAtPath = new List<ReferenceNode>( 2 );
Expand Down Expand Up @@ -1012,14 +1012,14 @@ private ReferenceNode SearchObject( object obj )
{
if( assetsToSearchSet.Count == 0 )
{
searchedUnityObjects.Add( unityObject.GetHashCode(), null );
searchedUnityObjects.Add( unityObject.GetInstanceID(), null );
return null;
}

assetPath = AssetDatabase.GetAssetPath( unityObject );
if( excludedAssetsPathsSet.Contains( assetPath ) || !AssetHasAnyReference( assetPath ) )
{
searchedUnityObjects.Add( unityObject.GetHashCode(), null );
searchedUnityObjects.Add( unityObject.GetInstanceID(), null );
return null;
}
}
Expand Down Expand Up @@ -1089,13 +1089,13 @@ private ReferenceNode SearchObject( object obj )
if( !searchingSourceAsset )
{
if( obj is Object )
searchedUnityObjects.Add( unityObject.GetHashCode(), result );
searchedUnityObjects.Add( unityObject.GetInstanceID(), result );
else
searchedObjects.Add( GetNodeObjectHash( obj ), result );
}
else if( result != null )
{
result.CopyReferencesTo( searchedUnityObjects[unityObject.GetHashCode()] );
result.CopyReferencesTo( searchedUnityObjects[unityObject.GetInstanceID()] );
PoolReferenceNode( result );
}
}
Expand Down Expand Up @@ -1229,7 +1229,7 @@ private bool TryGetReferenceNode( object nodeObject, out ReferenceNode reference
{
if( nodeObject is Object )
{
if( searchedUnityObjects.TryGetValue( nodeObject.GetHashCode(), out referenceNode ) )
if( searchedUnityObjects.TryGetValue( ( (Object) nodeObject ).GetInstanceID(), out referenceNode ) )
return true;
}
else if( searchedObjects.TryGetValue( GetNodeObjectHash( nodeObject ), out referenceNode ) )
Expand All @@ -1245,7 +1245,7 @@ private ReferenceNode GetReferenceNode( object nodeObject )
ReferenceNode result;
if( nodeObject is Object )
{
int hash = nodeObject.GetHashCode();
int hash = ( (Object) nodeObject ).GetInstanceID();
if( !searchedUnityObjects.TryGetValue( hash, out result ) || result == null )
{
result = PopReferenceNode( nodeObject );
Expand Down
2 changes: 1 addition & 1 deletion Plugins/AssetUsageDetector/Editor/SearchResultTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private bool GenerateRowsRecursive( TreeViewItem parent, ReferenceNode reference
if( linkDescriptions.Count > 0 )
{
Object prefabObject = PrefabUtility.GetCorrespondingObjectFromSource( unityObject );
if( prefabObject && parentData.node.HasLinkToObjectWithDescriptions( prefabObject.GetHashCode(), linkDescriptions ) )
if( prefabObject && parentData.node.HasLinkToObjectWithDescriptions( prefabObject.GetInstanceID(), linkDescriptions ) )
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Plugins/AssetUsageDetector/README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Asset Usage Detector (v2.3.0) =
= Asset Usage Detector (v2.3.1) =

Online documentation available at: https://github.com/yasirkula/UnityAssetUsageDetector
E-mail: [email protected]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.yasirkula.assetusagedetector",
"displayName": "Asset Usage Detector",
"version": "2.3.0",
"version": "2.3.1",
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
Expand Down

0 comments on commit d57a707

Please sign in to comment.