2
\$\begingroup\$

Is there any performance difference between [instantiate multiple prefabs] and [put all prefabs under a single parent prefab and then instantiate that parent prefab] in scene.
Hope you understand what i want to say.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ The usual answer to performance questions is "profile it on your target platform and find out!" You can set up a synthetic test where you spawn thousands of objects each way, and examine the average time for each method over multiple trials (to control for unrelated hiccups). \$\endgroup\$
    – DMGregory
    Oct 22, 2015 at 16:15
  • \$\begingroup\$ Is that work if i print Time.time before and after instantiating prefab thousand time in loop. Just guess \$\endgroup\$ Oct 22, 2015 at 16:45
  • 3
    \$\begingroup\$ Time.time probably won't have the resolution to get an accurate test, since it's only updated once each (physics/rendering) frame, and will include noise unrelated to the instantiation workload like rendering, vsync, and other scripts/processes. Consider either using Unity's built-in profiler, which will tell you how many ms each script took to run, or using your own instrumentation like System.Diagnostics.Stopwatch \$\endgroup\$
    – DMGregory
    Oct 22, 2015 at 16:49

1 Answer 1

0
\$\begingroup\$

Thanks to DMGregory.
I've got an answer so I post it.
When I instantiate multiple(20000) individual prefabs(using loop 20000 times) at once in my scene,
I get (573.73 to 463.63 Time ms and 43.81 to 30.63 Self ms)
but when I put 20 child prefabs to single parent and then instantiate parent prefab 1000 times in loop,
I get (290.18 to 290.00 Time ms and 2.93 to 2.92 Self ms)

So, second way is better and efficient for my case.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .