iOS Particle System: Short lag when spawning it for the first time

Hello,

I’m using a particle system that spawns 20 mesh particles (cubes) at once and throws them all over the place. When I spawn it for the first time I get a fairly huge spike lag - however, all spawns after this first initial one do not cause any lags (even if I spawn 3-4 of them simultaneously and I do not manually pool reuse the game objects at the moment). I guess Unity does some initialization of the particle system just-in-time when one is being spawned for the first time.

My question is what is the best idea to prevent this from happening. One simple solution would be to spawn one of the particle systems right at startup, pushing the initial lag to the first frame that is being rendered. However, I’m interested in what’s happening behind the scenes here and if there are better, less hacky approaches to fix it.

EDIT: The initial lag appears to be proportional to the number one enters in “Max Particles” in the particle system, so it is probably caused because Unity allocates this particle buffer when a particle system (of that type?) is being spawned for the first time. The initial question remains, is it possible to pre-allocate this without spawning one right at the start?

I know this is a couple weeks old, but could it be the size of your textures on the meshes? Your problem sounds similar to this one: Ralph Barbagallo - VR, AR, XR, Game Developer and Publisher

Tried Unity - Scripting API: Shader.WarmupAllShaders ?

Old question, but in case anyone else is struggling with this… I was having this issue, and it turned out to be caused by the fact that I was logging information with Debug.Log on instantiation of the particle system. I removed the logs, and the lag was gone.