- Home /
How to use pool to spawn object instead of instantiate?
In my racing game , when my car speed is above 80, new prefer is instantiate at the different location on the screen. this will make my game lil jerk when they came into my scene.
is there any solution about this.?
can i use pool to solve the problem?
how can i use it in my game instead of instatantiation?
plz help me...
but my problem is not how to use pool. i can easily search out this but i can't fix jerk problem...
Answer by Vipul-Dudharejiya · Jan 12, 2015 at 06:54 AM
hey ... i found the perfect solution for this. i have used following link to sol this issue.
[1]: https://www.assetstore.unity3d.com/cn/#!/content/19941
this is working for me...
Answer by kevinspawner · Dec 24, 2014 at 09:10 AM
Am not quiet sure why there is an jerk in instantiation call? Are you using Void Update or Void Fixed Update?
Try using Void Update and create a spawn points where exactly you want the Car to be spawned and also when instantiating you can create smooth effect by dividing the spawn position or offset by using co-routine.
Similar Example:
http://forum.unity3d.com/threads/simple-reusable-object-pool-help-limit-your-instantiations.76851/
Hope this helps.
In theory, if the object being Instantiated is "big" enough (piles of children, giant Start() script) and the CPU is slow enough, all the work during the Instantiate will cause you to drop a frame. Giving a small jerk. A pool would solve this, by pre-spawning the objects.
But hard to know if that's the problem (replace with balls and see if it goes away?) I've never seen an Instantiate cause a frame-drop (well, huge all-at-once particle effects.)
I am using "void FixedUpdate()" to call the method "StartCoroutine ("OneWaySpawn");" which will instantiate the opposite car in my game...
if car graphic is higher then it will cause jerk when they comes in to the play... whats solution about this...
If you use "Void Fixed Update()" it will force the physics to run in the fixed frame rate, So it will have some frame rate issues. In your case it will be jerky. I would suggest you to try to optimize the graphics, Also in "Start co-routine" try to create pool, this will optimize the performance. I would highly suggest you to use Void Update() for physics Game Objects, this should fix the problem.
in my case, how to use pool to spawn new object into the game
I have updated the answer, Check the link and it will explain you some basic pool and you can adapt it to your need.
Your answer
Follow this Question
Related Questions
spawn from pool only if pool has inactive gameobjects 3 Answers
instantiating vertically 2 Answers
How to Add Y Axis Offset to transform.localPosition on an Instantiated Prefab? 2 Answers
Referencing gameObject from script after Instantiate 0 Answers
Instantiating one prefab with different materials in one frame 0 Answers