Non blocking Error on returnToPool

Help, support and information for our Pro Pooling Unity Asset
Post Reply
Fabb
Posts: 30
Joined: Mon May 16, 2016 10:04 am

Non blocking Error on returnToPool

Post by Fabb » Wed May 25, 2016 12:42 pm

Hi,

I have a issue on return an object to the pool, it seems to be non blocking but it log an error.

Code: Select all

ReturnToPool: Object not managed by this object pool!
UnityEngine.Debug:LogError(Object)
FlipWebApps.ProPooling.Scripts.Pool`1:ReturnToPool(GameObject) (at Assets/FlipWebApps/ProPooling/Scripts/Pool.cs:238)
MapGenerator:returnToPool(GameObject) (at Assets/Script/Game/MapGenerator.cs:291)
DynamicLetters:destroyMe() (at Assets/Script/Game/DynamicLetters.cs:259)
My object had two hierarchy levels :

DynamicLetterPrefab
- DynamicLetterText (a text mesh)
- DynamicLetterObject ( a mesh)

Pro pooling instantiate works correctly in all cases (create, getfrompool ...) and i'm can see also that returntopool works correctly on returntopool because my gameobject come back to the root of hierarchy after his use.

I have use pro pooling since the beginning of my project with a prefab without hierarchy and it was working so good.

My code is working correctly with a prefab without hierarchy.

In MapGenerator.cs

Code: Select all

	
	public void returnToPool(GameObject _poolItem){
		_pool.ReturnToPool (_poolItem);
	}	
In the DynamicLetter.cs Destroy method element :

Code: Select all

	
	this.transform.rotation = Quaternion.Euler(new Vector3(0,0,0));
	this.transform.position = new Vector3(0,0,0);
	GameObject.Find ("MatrixPanelLetters").GetComponent<MapGenerator> ().returnToPool (this.gameObject);
Have you a idea about this glitch ?

Thanks :)

mahewitt
Site Admin
Posts: 252
Joined: Thu May 05, 2016 8:06 pm

Re: Non blocking Error on returnToPool

Post by mahewitt » Wed May 25, 2016 6:17 pm

Hi Fabrice,

I just tried modifying the PoolManagerCreatedPool demo by adding child objects to the CubeWirhParticles prefab and that seemed to work without problem.

When you get an item from the pool, it is added to a list:

_inUseInstances.Add(poolItem.GameObject, poolItem);

On adding back there is a check that it is valid Pool.cs ln.233:

if (_inUseInstances.TryGetValue(gameObject, out poolItem))
{
return ReturnToPool(poolItem);
}
else
Debug.LogError("ReturnToPool: Object not managed by this object pool!");

Without other code changes - if you take a prefab without children and add one do you still get the same error?

Mark

Fabb
Posts: 30
Joined: Mon May 16, 2016 10:04 am

Re: Non blocking Error on returnToPool

Post by Fabb » Thu May 26, 2016 8:10 pm

Hi Mark,

Thanks for your response.
I have no issue when i use a prefab without children.
I tried a modification of your demo by adding an empty gameobject named ParentCube wich include the RedCube.
After i have modified your script, i have a lot of issue (no the same i had), i think i don't understand mechanism ...

If you can help, it will be great :)

Thanks.
Fabrice

ps : i have also modified the 1.PoolManagerCreatedPool by adding an empty gameobject named Parent which include LifeCyclePrefab and i have an issue. After delete my prefab an put again the last LifeCyclePrefab directly i have an issue too ... is there a cache ? i restart Unity and i have the same problem ... i use 5.3.4f1 version.

Code: Select all

NullReferenceException: Object reference not set to an instance of an object
FlipWebApps.ProPooling._Demo.Scripts.PoolManagerCreatedPool.Start () (at Assets/FlipWebApps/ProPooling/_Demo/Scripts/PoolManagerCreatedPool.cs:52)

Code: Select all

namespace FlipWebApps.ProPooling._Demo.Scripts
{

    public class GraphicalDemoSpawnerPooled : MonoBehaviour
    {
        public GameObject Prefab;
        public float SpawnDelay;
        public float Velocity;
        public Text Display;

        Pool<CustomPoolItem> _pool;
        float _counter;
        double _totalTime;

        ///
        ///  get a reference to the pool for speed.
        /// 
        void Start()
        {
            _pool = new Pool<CustomPoolItem>(Prefab, 100);
        }

        /// <summary>
        /// Create items
        /// </summary>
        void Update()
        {
            _counter += Time.deltaTime;
            if (_counter > SpawnDelay)
            {
                var spawnTime = DateTime.Now;

                var poolItem = _pool.GetPoolItemFromPool(new Vector3(0, 0, Random.Range(-2, 2)), Quaternion.identity, transform);
                //poolItem.Rigidbody.velocity = transform.up*Velocity;
				poolItem.GameObject.transform.FindChild("CubeRed").GetComponent<Rigidbody>().velocity = transform.up*Velocity;
				//Debug.Log("Nb child" + poolItem.GameObject.transform.childCount);
                _counter = 0;
                _totalTime += (DateTime.Now - spawnTime).TotalMilliseconds;
            }

            Display.text = "Pooled Time: " + (int)_totalTime + "ms";
        }


        /// <summary>
        /// Custom Pool Item that cached a reference to RigidBody and sets up the generated items.
        /// </summary>
        public class CustomPoolItem : PoolItem
        {
            public Rigidbody Rigidbody { get; set; }

            public override void OnSetup()
            {
                base.OnSetup();
                // cache rigid body reference for speed
				Rigidbody = GameObject.transform.FindChild("CubeRed").GetComponent<Rigidbody>();

                // Set pool reference so the component can return this back to the pool
				GameObject.transform.FindChild("CubeRed").GetComponent<GraphicalDemoItemPooled>().CustomPoolItem = this;
            }
        }
    }
}

mahewitt
Site Admin
Posts: 252
Joined: Thu May 05, 2016 8:06 pm

Re: Non blocking Error on returnToPool

Post by mahewitt » Fri May 27, 2016 6:32 am

Hi,

The null reference is because you will need to update the prefab on both the PoolManager and also the Demo-(PoolManagerCreatedPool gameobject / component) for this to work in the demo. I didn't add more error handling code here as it is only a demo of the features and not part of the actual pooling framework.

As for the other error, the code below looks like it should work so long as the FindChild and GetComponent calls don't return null. What is the error you are getting for that part and at what part does it happen (get from pool, return, ...)?

Mark

Fabb
Posts: 30
Joined: Mon May 16, 2016 10:04 am

Re: Non blocking Error on returnToPool

Post by Fabb » Fri May 27, 2016 4:15 pm

Hi Mark,

The issue is solved with the demo. I haven't seen the second modification to do.
I can reproduce the returntopool issue with your demo with my mistake.
I'll worked on my own code :)

Thanks.

Fabb
Posts: 30
Joined: Mon May 16, 2016 10:04 am

Re: Non blocking Error on returnToPool

Post by Fabb » Fri May 27, 2016 8:42 pm

Hi Mark,

I have the same issue on my code.
I think the problem in on the variable type on my main.


After initialisation of my pool on my main program with :

Code: Select all

		
_pool = new Pool<PoolItem>(letterObjectPrefab, 100);
I instantiate poolobjects from a main with :

Code: Select all

					
var poolItem = _pool.GetFromPool (bLetterPosition, Quaternion.Euler(new Vector3(0,0,0)), this.transform);
poolItem.GetComponent<DynamicLetters> ().initLetter ();
I have this code to returntopool :

Code: Select all

	
public void returnToPoolEffects(GameObject _poolItem){
	_poolEffects.ReturnToPool (_poolItem);
}
All objects live their life and they destroy themself after a time :

Code: Select all

GameObject.Find ("MatrixPanelLetters").GetComponent<Main> ().returnToPool (this.gameObject);
With a simple object prefab without hierarchy, this code works.
With a hierarchical object prefab, i have this error code message.
Objects are come back the pool.

Code: Select all

ReturnToPool: Object not managed by this object pool!
UnityEngine.Debug:LogError(Object)
FlipWebApps.ProPooling.Scripts.Pool`1:ReturnToPool(GameObject) (at Assets/FlipWebApps/ProPooling/Scripts/Pool.cs:238)
MapGenerator:returnToPool(GameObject) (at Assets/Script/Game/Main.cs:297)
DynamicLetters:destroyMe() (at Assets/Script/Game/DynamicLetters.cs:259)
I have tried another method by returntopool inside the object pool, i have the same error message.

Did you have idea ?

mahewitt
Site Admin
Posts: 252
Joined: Thu May 05, 2016 8:06 pm

Re: Non blocking Error on returnToPool

Post by mahewitt » Sat May 28, 2016 9:11 am

Hi,

Looking at the code, I noticed one thing and that is that getting from the pool references _pool yet the returnToPoolEffects method uses _poolEffects. Are these the same reference, or is there a separate method that you use for returning to _pool (I see the error mentions MapGenerator:returnToPool).

Also is the code GameObject.Find ("MatrixPanelLetters").GetComponent<Main> ().returnToPool (this.gameObject); called from within a component that is on the root of the prefab hierarchy to make sure that the this.GameObject reference is actually returning the retrieved pool item root gameobject and not something else?

Hope this helps. If not then drop me a mail and perhaps we can try for a screen sharing session so I can get a better look..

Regards,
Mark

Post Reply