- Home /
iTween and pooled gameObjects
I am using an object pooling system to spawn and un-spawn projectiles. The projectiles are animated using iTween, however the issue that I am having is that every time the pool spawns a new object it adds a new iTween component, instead of just playing the animation again. So the issue I am running into is mutliple itween components are added to the game object and the animation gets crazy. What is the best way to approach using itween animations with an object pooling system?
I figured something out, it may not be the best solution, but here is what I am doing .. on my projectile, before it un-spawns I have it remove every iTween component IE
while (gameObject.GetComponent (iTween)){ Destroy (gameObject.GetComponent (iTween)); yield; } //then unspawn
Thanks for looking, hope this helps anyone else with the same issue.
I wanted to note as the pool goes on and the object is recycled over and over the iTween components start getting a little off. I still havent figured out a good way to repeat an iTween animation without destroying and instantiating it again.
Although there are probably some ways to do what you want, if I were you I would probably try to eli$$anonymous$$ate the need for iTween in these pooled objects. Code them in a way that their motion is completely in your control, and then you can decide how to reset them on your Despawn().
Another option, is to have the objects themselves use iTween (as opposed to an external caller), so they call it in OnSpawn() and before they Despawn() themselves, they wait for the tween to end.
Hey thanks for the input DannyB, I will do some more testing with this and post my results. The reason I am using iTween for these projectiles is that I am needing an arching projectile and I wanted to fake it rather than calculate physics for it to try and speed things up for mobile. I'll let you know how it goes.
I understand. iTween indeed helps with a lot of things that otherwise you would have to code yourself. I started like you with a lot of tweens, but then decided to move most of my stuff to self-calculated Update().
If you decide that you prefer iTween for this, then probably one of the leading approaches for you (without knowing your exact circumstances) would be for the object to control its own movement (tween) and its own Despawning. Once these two tasks are coupled at the same logical unit, it will be easier for you to build the spawn/despawn logic so it stays friendly with iTween.
Your answer
Follow this Question
Related Questions
Pooling object performs the same or worse than instantiate/destroy? 1 Answer
Resource Being Deactivated 0 Answers
How to control pooledObject? 1 Answer
pooled prefab missing child 1 Answer
Object pooling question. 0 Answers