diff --git a/Assets/UnityPooler/Scripts/GameObjectPool.cs b/Assets/UnityPooler/Scripts/GameObjectPool.cs
index 379838f..c11e8a5 100644
--- a/Assets/UnityPooler/Scripts/GameObjectPool.cs
+++ b/Assets/UnityPooler/Scripts/GameObjectPool.cs
@@ -20,7 +20,7 @@ public static class GameObjectPool
/// The prefab or GameObject that we
/// want a duplicated object of.
/// A GameObject from the object pool.
- public static GameObject GetObj(GameObject objToCreateFrom)
+ public static GameObject GetObj(GameObject objToCreateFrom, bool gameObjectActiveState = true)
{
PoolableGameObject poolable = objToCreateFrom.GetComponent();
@@ -30,7 +30,7 @@ public static GameObject GetObj(GameObject objToCreateFrom)
return null;
}
- return poolable.Get().gameObject;
+ return poolable.Get(gameObjectActiveState).gameObject;
}
///
@@ -112,9 +112,9 @@ public static void IncrementPoolWithObj(GameObject objToInc)
///
///
///
- public static GameObject Get(this GameObject obj)
+ public static GameObject Get(this GameObject obj, bool gameObjectActiveState = true)
{
- return GetObj(obj);
+ return GetObj(obj, gameObjectActiveState);
}
///
diff --git a/Assets/UnityPooler/Scripts/PoolableGameObject.cs b/Assets/UnityPooler/Scripts/PoolableGameObject.cs
index a3e099e..b681967 100644
--- a/Assets/UnityPooler/Scripts/PoolableGameObject.cs
+++ b/Assets/UnityPooler/Scripts/PoolableGameObject.cs
@@ -1,4 +1,4 @@
-using UnityEngine;
+using UnityEngine;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
@@ -121,7 +121,7 @@ public void Release()
transform.SetParent(container, false);
gameObject.SetActive(false);
_originalObject._pooledObjs.Push(this);
- _numOfActiveObjs--;
+ _originalObject._numOfActiveObjs--;
}
///
@@ -234,8 +234,8 @@ public void ReleaseObjectsAndClearPool()
[System.NonSerialized]
private bool _initialized;
- [System.NonSerialized]
- private IGameObjectPoolable[] _poolables;
+ //[System.NonSerialized]
+ //private IGameObjectPoolable[] _poolables;
///
/// The function that will be called for reuse on MonoBehaviours. Change this if it conflicts.
@@ -369,7 +369,7 @@ private void SendCreationMessage(PoolableGameObject newObj)
onObjectCreation(newObj.gameObject);
}
- _poolables = GetComponentsInChildren(true);
+ var _poolables = newObj.GetComponentsInChildren(true);
for (int i = 0; i < _poolables.Length; i++)
{
@@ -397,6 +397,8 @@ private PoolableGameObject ReuseObject()
}
while (objToUse == null || objToUse.gameObject == null || !objToUse._isActive);
+ var _poolables = objToUse.GetComponentsInChildren(true);
+
for (int i = 0; i < _poolables.Length; i++)
{
_poolables[i].OnObjectReused();
@@ -472,4 +474,4 @@ private void OnDestroy()
#endregion
}
-}
\ No newline at end of file
+}