- Home /
Problem with object pooling and reseting the properties of a pooled object
I am using object pooling in order to create the human-characters that follow an A* path to get to their target, then dissapear and be reused again from the original spot. Very first instances work just fine, but the repooled instances get activated at the spot where they have been deactivated. I tried to save the original position and use it for reactivated ones, however it doesn't work as well as pathfinding script. public float hTime = 3f; public Transform pos;
void Start () {
InvokeRepeating("Create", hTime, hTime);
}
void Create()
{
GameObject obj = Pooler.current.GetPooledObject();
if (obj == null) return;
Debug.Log(transform.position);
obj.transform.position = pos;
obj.transform.rotation = transform.rotation;
obj.SetActive(true);
}
What is your pooler looks like? Gameobjects from the pool should be available to change their transform, I don't see what can prevent you to do that...
So my problem goes deeper. I also use RVO library for agents to avoid collisions. Each agent has a script RVOagent, which with its Start function adds this cagent to a simulation powered by RVO2Simulator script. When I reactivate my agent, the RVO agent script doesn't restart, thus my agent is already considered that he has reached his final target in RVOSimulator script. I tried to disable the RVO agent script after deactivating the agent, when I activate it with agent it doesn't run its start function because it runs only once in scripts runtime. So now the question will be probably how to restart this script for agent when it has been reactivated.
Your answer
Follow this Question
Related Questions
Pooled objects change behavior. 0 Answers
spawn from pool only if pool has inactive gameobjects 3 Answers
Pooling object performs the same or worse than instantiate/destroy? 1 Answer
General pooling question 1 Answer
How to control pooledObject? 1 Answer