@@ -8,8 +8,8 @@ public sealed class Pool
88 private Poolable _prefab = null ;
99 private Stack < Poolable > _instances = null ;
1010
11- private static Dictionary < GameObject , Pool > _prefabLookup = new Dictionary < GameObject , Pool > ( ) ;
12- private static Dictionary < GameObject , Pool > _instanceLookup = new Dictionary < GameObject , Pool > ( ) ;
11+ private static Dictionary < int , Pool > _prefabLookup = new Dictionary < int , Pool > ( ) ;
12+ private static Dictionary < int , Pool > _instanceLookup = new Dictionary < int , Pool > ( ) ;
1313
1414 public Pool ( GameObject prefab )
1515 {
@@ -23,12 +23,12 @@ public Pool(GameObject prefab)
2323 }
2424
2525 _instances = new Stack < Poolable > ( ) ;
26- _prefabLookup . Add ( prefab , this ) ;
26+ _prefabLookup . Add ( prefab . GetHashCode ( ) , this ) ;
2727 }
2828
2929 public static Pool GetPrefabPool ( GameObject prefab )
3030 {
31- bool hasPool = _prefabLookup . TryGetValue ( prefab , out var pool ) ;
31+ bool hasPool = _prefabLookup . TryGetValue ( prefab . GetHashCode ( ) , out var pool ) ;
3232
3333 if ( ! hasPool )
3434 pool = new Pool ( prefab ) ;
@@ -37,7 +37,7 @@ public static Pool GetPrefabPool(GameObject prefab)
3737 }
3838
3939 public static bool TryGetInstancePool ( GameObject instance , out Pool pool ) =>
40- _instanceLookup . TryGetValue ( instance , out pool ) ;
40+ _instanceLookup . TryGetValue ( instance . GetHashCode ( ) , out pool ) ;
4141
4242 public void Populate ( int count )
4343 {
@@ -124,7 +124,7 @@ private Poolable GetInstance()
124124 private Poolable CreateInstance ( )
125125 {
126126 var instance = Object . Instantiate ( _prefab ) ;
127- _instanceLookup . Add ( instance . gameObject , this ) ;
127+ _instanceLookup . Add ( instance . gameObject . GetHashCode ( ) , this ) ;
128128
129129 return instance ;
130130 }
0 commit comments