Skip to content

Commit d57a707

Browse files
committed
Fixed exceptions while searching for some URP assets' references due to their overriden GetHashCode functions
1 parent 3fa3344 commit d57a707

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public SearchResult Run( Parameters searchParameters )
350350

351351
// Initialize the nodes of searched asset(s)
352352
foreach( Object obj in objectsToSearchSet )
353-
searchedUnityObjects.Add( obj.GetHashCode(), PopReferenceNode( obj ) );
353+
searchedUnityObjects.Add( obj.GetInstanceID(), PopReferenceNode( obj ) );
354354

355355
// Progressbar values
356356
int searchProgress = 0;
@@ -672,7 +672,7 @@ private void CalculateUnusedObjects( List<SearchResultGroup> searchResult, out H
672672
else
673673
{
674674
for( Transform parent = ( (GameObject) obj ).transform.parent; parent != null; parent = parent.parent )
675-
usedObjectPathsSet.Add( parent.gameObject.GetHashCode().ToString() );
675+
usedObjectPathsSet.Add( parent.gameObject.GetInstanceID().ToString() );
676676
}
677677
}
678678
}
@@ -739,13 +739,13 @@ private void CalculateUnusedObjects( List<SearchResultGroup> searchResult, out H
739739
if( !searchedTopmostGameObject )
740740
{
741741
if( obj is GameObject )
742-
unusedMainObjectNodes[obj.GetHashCode().ToString()] = node;
742+
unusedMainObjectNodes[obj.GetInstanceID().ToString()] = node;
743743
else
744744
currentSearchResultGroup.AddReference( node );
745745
}
746746
else // List child GameObject scene objects under their parent GameObject
747747
{
748-
string dictionaryKey = searchedTopmostGameObject.GetHashCode().ToString();
748+
string dictionaryKey = searchedTopmostGameObject.GetInstanceID().ToString();
749749
List<ReferenceNode> unusedSubObjectNodesAtPath;
750750
if( !unusedSubObjectNodes.TryGetValue( dictionaryKey, out unusedSubObjectNodesAtPath ) )
751751
unusedSubObjectNodes[dictionaryKey] = unusedSubObjectNodesAtPath = new List<ReferenceNode>( 2 );
@@ -1012,14 +1012,14 @@ private ReferenceNode SearchObject( object obj )
10121012
{
10131013
if( assetsToSearchSet.Count == 0 )
10141014
{
1015-
searchedUnityObjects.Add( unityObject.GetHashCode(), null );
1015+
searchedUnityObjects.Add( unityObject.GetInstanceID(), null );
10161016
return null;
10171017
}
10181018

10191019
assetPath = AssetDatabase.GetAssetPath( unityObject );
10201020
if( excludedAssetsPathsSet.Contains( assetPath ) || !AssetHasAnyReference( assetPath ) )
10211021
{
1022-
searchedUnityObjects.Add( unityObject.GetHashCode(), null );
1022+
searchedUnityObjects.Add( unityObject.GetInstanceID(), null );
10231023
return null;
10241024
}
10251025
}
@@ -1089,13 +1089,13 @@ private ReferenceNode SearchObject( object obj )
10891089
if( !searchingSourceAsset )
10901090
{
10911091
if( obj is Object )
1092-
searchedUnityObjects.Add( unityObject.GetHashCode(), result );
1092+
searchedUnityObjects.Add( unityObject.GetInstanceID(), result );
10931093
else
10941094
searchedObjects.Add( GetNodeObjectHash( obj ), result );
10951095
}
10961096
else if( result != null )
10971097
{
1098-
result.CopyReferencesTo( searchedUnityObjects[unityObject.GetHashCode()] );
1098+
result.CopyReferencesTo( searchedUnityObjects[unityObject.GetInstanceID()] );
10991099
PoolReferenceNode( result );
11001100
}
11011101
}
@@ -1229,7 +1229,7 @@ private bool TryGetReferenceNode( object nodeObject, out ReferenceNode reference
12291229
{
12301230
if( nodeObject is Object )
12311231
{
1232-
if( searchedUnityObjects.TryGetValue( nodeObject.GetHashCode(), out referenceNode ) )
1232+
if( searchedUnityObjects.TryGetValue( ( (Object) nodeObject ).GetInstanceID(), out referenceNode ) )
12331233
return true;
12341234
}
12351235
else if( searchedObjects.TryGetValue( GetNodeObjectHash( nodeObject ), out referenceNode ) )
@@ -1245,7 +1245,7 @@ private ReferenceNode GetReferenceNode( object nodeObject )
12451245
ReferenceNode result;
12461246
if( nodeObject is Object )
12471247
{
1248-
int hash = nodeObject.GetHashCode();
1248+
int hash = ( (Object) nodeObject ).GetInstanceID();
12491249
if( !searchedUnityObjects.TryGetValue( hash, out result ) || result == null )
12501250
{
12511251
result = PopReferenceNode( nodeObject );

Plugins/AssetUsageDetector/Editor/SearchResultTreeView.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private bool GenerateRowsRecursive( TreeViewItem parent, ReferenceNode reference
299299
if( linkDescriptions.Count > 0 )
300300
{
301301
Object prefabObject = PrefabUtility.GetCorrespondingObjectFromSource( unityObject );
302-
if( prefabObject && parentData.node.HasLinkToObjectWithDescriptions( prefabObject.GetHashCode(), linkDescriptions ) )
302+
if( prefabObject && parentData.node.HasLinkToObjectWithDescriptions( prefabObject.GetInstanceID(), linkDescriptions ) )
303303
return false;
304304
}
305305
}

Plugins/AssetUsageDetector/README.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= Asset Usage Detector (v2.3.0) =
1+
= Asset Usage Detector (v2.3.1) =
22

33
Online documentation available at: https://github.com/yasirkula/UnityAssetUsageDetector
44

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.yasirkula.assetusagedetector",
33
"displayName": "Asset Usage Detector",
4-
"version": "2.3.0",
4+
"version": "2.3.1",
55
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
66
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
77
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",

0 commit comments

Comments
 (0)