com.amanotes.prefabpool 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.1.0] - 2026-10-06
4
+
5
+ ### Added
6
+ - `PrefabPool.ReleaseForSceneChange()` - lets a pool outlive the scene that used it: returns every checked-out instance to its pool and drops scene-bound spawn parents. Pooled instances stay alive; re-register the groups with the next scene's parents.
7
+
8
+ ## [2.0.3] - 2026-09-24
9
+
10
+ ### Added
11
+ - `IPrefabPool.TryReturn` / `PoolGroup.TryReturn` — returns whether the instance was in the checkout ledger (`Return` remains a silent no-op when unknown).
12
+
3
13
  ## [2.0.2] - 2026-09-14
4
14
 
5
15
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  # PrefabPool API Reference
2
2
 
3
- **Package:** `com.amanotes.prefabpool` | **Version:** 2.0.2 | **Namespace:** `Amanotes.Core`
3
+ **Package:** `com.amanotes.prefabpool` | **Version:** 2.1.0 | **Namespace:** `Amanotes.Core`
4
4
 
5
5
  Generic object pooling system to eliminate garbage collection spikes from frequent instantiation/destruction.
6
6
 
@@ -370,3 +370,15 @@ var unknown = group.Get("unknown_id");
370
370
  ## See Also
371
371
 
372
372
  - [PrefabPool README](../README.md)
373
+
374
+ ---
375
+
376
+ ## Outliving a scene
377
+
378
+ `PrefabPool.ReleaseForSceneChange()` lets a pool survive the scene that used it (for example a pool in `DontDestroyOnLoad`):
379
+
380
+ - every checked-out instance is returned to its pool;
381
+ - scene-bound spawn parents are dropped (`group.Register(pool, null)`);
382
+ - pooled instances stay alive.
383
+
384
+ Call `RegisterGroup(group, newSpawnParent)` again once the next scene's parent exists. No-op after `MarkShutdown()` / `DestroyPool()`.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # PrefabPool
2
2
 
3
3
  **Package:** `com.amanotes.prefabpool`
4
- **Version:** 2.0.2
4
+ **Version:** 2.1.0
5
5
 
6
6
  Generic object pooling system for Unity with lifecycle callbacks and material pooling support.
7
7
 
@@ -30,7 +30,7 @@ Add the package to your Unity project via `Packages/manifest.json`:
30
30
  ```json
31
31
  {
32
32
  "dependencies": {
33
- "com.amanotes.prefabpool": "2.0.2"
33
+ "com.amanotes.prefabpool": "2.1.0"
34
34
  },
35
35
  "scopedRegistries": [
36
36
  {
@@ -1,7 +1,9 @@
1
1
  using System;
2
2
  using System.Collections;
3
3
  using System.Collections.Generic;
4
+ #if UNITY_EDITOR
4
5
  using UnityEditor;
6
+ #endif
5
7
  using UnityEngine;
6
8
  using UnityObject = UnityEngine.Object;
7
9
 
@@ -196,6 +198,12 @@ namespace Amanotes.Core
196
198
  {
197
199
  _prefabPool?.Return(this, gameObject);
198
200
  }
201
+
202
+ public bool TryReturn(GameObject gameObject)
203
+ {
204
+ if (_prefabPool == null || gameObject == null) return false;
205
+ return _prefabPool.TryReturn(this, gameObject);
206
+ }
199
207
 
200
208
  public Transform SpawnParent => _spawnParent;
201
209
  }
@@ -207,6 +215,8 @@ namespace Amanotes.Core
207
215
  void SetSpawnParent(string groupId, Transform spawnParent);
208
216
  GameObject Get(PoolGroup group, string prefabId, Vector3 localPosition = default, Transform customParent = null);
209
217
  void Return(PoolGroup group, GameObject gameObject);
218
+ /// <summary>Returns false when the instance was not checked out from this pool (silent no-op in <see cref="Return"/>).</summary>
219
+ bool TryReturn(PoolGroup group, GameObject gameObject);
210
220
  IEnumerator Initialize();
211
221
  /// <summary>
212
222
  /// Marks the pool as shut down so all subsequent Get/Return calls no-op safely.
@@ -362,6 +372,29 @@ namespace Amanotes.Core
362
372
  public bool IsReady => _isReady;
363
373
 
364
374
  public void MarkShutdown() => _isDestroyed = true;
375
+
376
+ /// <summary>
377
+ /// Lets the pool outlive the scene that used it: returns every checked-out instance to its pool and drops
378
+ /// scene-bound spawn parents. Pooled instances stay alive; re-register the groups with the next scene's parents.
379
+ /// </summary>
380
+ public void ReleaseForSceneChange()
381
+ {
382
+ if (_isDestroyed) return;
383
+
384
+ var liveIds = new List<UnityObjectId>(_liveInstances.Keys);
385
+ for (var i = 0; i < liveIds.Count; i++)
386
+ {
387
+ var id = liveIds[i];
388
+ var go = _liveInstances[id];
389
+ if (go != null && _instanceTypeMap.TryGetValue(id, out var entry))
390
+ entry.Return(go, transform);
391
+ _instanceTypeMap.Remove(id);
392
+ _liveInstances.Remove(id);
393
+ }
394
+
395
+ for (var i = 0; i < _groupOrder.Count; i++)
396
+ _groupOrder[i].Register(this, null);
397
+ }
365
398
 
366
399
  public void RegisterGroup(PoolGroup group, Transform spawnParent)
367
400
  {
@@ -418,15 +451,21 @@ namespace Amanotes.Core
418
451
 
419
452
  public void Return(PoolGroup group, GameObject go)
420
453
  {
421
- if (_isDestroyed || group == null || go == null) return;
422
-
454
+ TryReturn(group, go);
455
+ }
456
+
457
+ public bool TryReturn(PoolGroup group, GameObject go)
458
+ {
459
+ if (_isDestroyed || group == null || go == null) return false;
460
+
423
461
  var instanceId = UnityObjectIdentity.GetId(go);
424
- if (_instanceTypeMap.TryGetValue(instanceId, out var entry))
425
- {
426
- entry.Return(go, transform);
427
- _instanceTypeMap.Remove(instanceId);
428
- _liveInstances.Remove(instanceId);
429
- }
462
+ if (!_instanceTypeMap.TryGetValue(instanceId, out var entry))
463
+ return false;
464
+
465
+ entry.Return(go, transform);
466
+ _instanceTypeMap.Remove(instanceId);
467
+ _liveInstances.Remove(instanceId);
468
+ return true;
430
469
  }
431
470
 
432
471
  private void PurgeStaleInstanceMap()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.amanotes.prefabpool",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "displayName": "[Ama] Prefab Pool",
5
5
  "description": "Generic object pooling system for Unity",
6
6
  "unity": "2022.3",