@@ -344,7 +344,7 @@ public class GameObjectPool : ObjectPoolBase<GameObject>
344344 /// If true then when the object is despawned back to the pool will be parented to the same as the sample entity
345345 /// parent transform
346346 /// </summary>
347- public bool DespawnToSampleParent { get ; set ; }
347+ public bool DespawnToSampleParent { get ; set ; } = true ;
348348
349349 public GameObjectPool ( uint initSize , GameObject sampleEntity ) : base ( initSize , sampleEntity , Instantiator )
350350 {
@@ -375,7 +375,7 @@ public static GameObject Instantiator(GameObject entityRef)
375375
376376 protected override GameObject SpawnEntity ( )
377377 {
378- var entity = SpawnEntity ( ) ;
378+ var entity = base . SpawnEntity ( ) ;
379379
380380 entity . SetActive ( true ) ;
381381
@@ -403,7 +403,7 @@ public class GameObjectPool<T> : ObjectPoolBase<T> where T : Behaviour
403403 /// If true then when the object is despawned back to the pool will be parented to the same as the sample entity
404404 /// parent transform
405405 /// </summary>
406- public bool DespawnToSampleParent { get ; set ; }
406+ public bool DespawnToSampleParent { get ; set ; } = true ;
407407
408408 public GameObjectPool ( uint initSize , T sampleEntity ) : base ( initSize , sampleEntity , Instantiator )
409409 {
@@ -442,14 +442,17 @@ protected override T SpawnEntity()
442442 {
443443 T entity = null ;
444444
445- do
445+ while ( entity == null )
446446 {
447- entity = SpawnEntity ( ) ;
447+ entity = base . SpawnEntity ( ) ;
448+
449+ if ( entity . gameObject == null )
450+ {
451+ SpawnedEntities . Remove ( entity ) ;
452+
453+ entity = null ;
454+ }
448455 }
449- // ReSharper disable once ConditionIsAlwaysTrueOrFalse
450- // Need to do while loop and check as parent objects could have destroyed the entity/gameobject before it could
451- // be properly disposed by pool service
452- while ( entity == null || entity . gameObject == null ) ;
453456
454457 entity . gameObject . SetActive ( true ) ;
455458
0 commit comments