Problems with GameObject Pooling

Hey There, at first i wanna say thank you for your very usefull tool. :heart_eyes:
Sadly i couldnt figure out how to use it properly yet.

I am working on a 2D Project in Unity.
and i run into some problems while i was working with gameobject pooling.
Sometimes they did clip through gridgraph sometimes they just stoped walking at some random point.
After i disable them i also tried to set their target null which diddnt change their random behaviour.

Now i did read in a previous post that if we are use pooling and de and activate game objects you said this here:

where do i have to call the onDisable function in order to solve this issues? yet my unitScript has a kill method
which checks its healthpoint if its equal or under 0 it will deactivate the gameobject, but i did not understand where to use the OnDisable method. Can You explain a little bit further please?

CaveDave

The OnDisable method is called by Unity, your scripts should not have to do anything.

I’m not sure why that would be happening. Do you see a green path in the scene view? If so, does it go to the correct destination? Do you have a video of the issue happening?

I uploaded 2 samples in one video on youtube the Link is here:

0:00 - 0:16 shows that they just stops

  • 0:16 shows they clip and stoping randomly.

I only see one green path most of the time.
I noticed that the first wave where the GO get activated the first time they never have issues.
But after the first one they start to appear in some random way and not on every GO that has been activated before.

If i do instaniate and kill them all the time, there is no problem at all, this only happens if i use pooling.

Here also an image of my A* settings

Hmm… There might be a bug in your version.

Try to add this line to the AIPath.OnDisable method:

interpolator = new PathInterpolator();

Ok that helped a lot i guess. they wont clip anymore, and they seem to have a way more solid waypoint.
But now still there are a couple of GameObjects that dont start walking when they get actiated, and just stays at the startpoint doing nothing even they have a target active

but this only happens after they have been activated once, the first time they never mess up no matter how much will get activated on the first round.

I’m not sure why that is happening. I thought I tested disabling/enabling components with the previous version.
In any case. I have added a unit test for pooling to my current version. So if it is ok to disable object pooling for now I will make sure it works for you when the next version is released.

Yeah sure im glad your looking at it. Thank you :slight_smile: