Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Allocating particles at the start of the game to prevent lags on creation
#1
In my game player is creating softbodies in runtime. Now, when it happens game lags a little. I assume its happens because at the moment of softbody creation obi solver does not have needed amount of particles and it creates new ones. Can I somehow tell obi solver to create some amount of particles at the start of the game? Im already using object pool for softbodies but even though Im instantiating some amount of softbodies at the start and releasing them but solver does not create particles for them probably because Im creating and releasing softbodies too fast. My current solution is to instantiate softbodies at the start and after 1-2 frames release those softbodies. This way solver is creating needed particles and game does not lag on creation of new softbodies
Reply
#2
(28-05-2024, 02:00 PM)bozdo Wrote: In my game player is creating softbodies in runtime. Now, when it happens game lags a little. I assume its happens because at the moment of softbody creation obi solver does not have needed amount of particles and it creates new ones.

Hi!

When you add an actor to a solver and the current list of particles is not long enough, the list is resized. This is just a list allocating memory internally, shouldn't be noticeable at all. Is this measurable in the profiler?

(28-05-2024, 02:00 PM)bozdo Wrote: My current solution is to instantiate softbodies at the start and after 1-2 frames release those softbodies. This way solver is creating needed particles and game does not lag on creation of new softbodies

If this only happens in-editor, it could be that you're using async compilation with Burst which will cause the compiler to compile your code at runtime, when it is about to be used. This would explain why creating a few softbodies and then releasing them prevents the hiccup. The solution in this case would be to enable synchronous compilation: Jobs->Burst->Synchronous compilation.

It could also be shader compilation, if the shader used by your softbodies hasn't been used before.
Reply