Hi, I have a tunnel in my game composed of many, many, many spheres that shrink and grow. For this I use a timeline which works well. The performance takes a huge hit however. This is what the tunnel looks like:
Unplugging the timeline removes all the performance issues so that is definitely the problem here.
Is there a better way to do this other than a looping timeline for each sphere? Can I instance them somehow? Or is this just not possible at this scale?
First and foremost:
You will get a better perfomance by disabling collision and disabling overlap events. Every transform change triggers an overlap check on all of the other overlap-able shapes.
If you need collisions for a player use non-movable custom collision shapes (like built-in invisible wall actor)
also, you will get better perfomance with one “timeline manager blueprint” while all of the spheres track it instead of all of the spheres making their own.
But the best solution for visual-only changes would be to use a material. Then it’s all on the GPU and there’s no tick / timeline overhead. One implementaion is here, but there are plenty of tutorials on that.
I need them to have accurate collision because the player dies when colliding with them. I am currently using the hit event to check this. I cant really use a stationary collision box for this as the player is meant to wait for the spheres to shrink down to jump through. This means that if I would use a stationary collision, the player could jump through even when they are fully expanded.
For the manager, how would that function exactly? Would I make a blueprint that has an array of all the spheres, then use a for each loop with a timeline? Or is there a more efficient way?
Will try disabling overlap events and stuff and see how much it helps! Thanks for the tips
Yes, exactly.
Keep in mind that ForEachLoop macros get exponentially heavier with big arrays (better not exceed ~100 elements). If you can, use C++ for that instead, or use other optimization technics, like skipping every ‘n’ tick for spheres further away etc.
If you have to use collisions for each sphere, make sure they are Simple, not Complex (you can check this in the Static Mesh Editor).
Okay, I can’t use c++ in this project unfortunately. I currently have about 400 spheres… might be able to lower it a bit. Otherwise I’ll look into what you’re talking about!
The sphere is just the default unreal sphere but with a custom material. So should be using simple collision already! I will double check though
Cool!
Start with making a simple manager and see if that suffices, then add further layers if needed, always one at the time so you can easily track what actually helps (and what makes it worse).
Using Instanced Spheres instead of making them separate actors could help a lot as well.
Be sure to check if you’re optimizng right stuff. For example if I’m suggesting collisions - first try to disable all of the collisions and see if helps at all, before you try to optimize it. I’m talking from my previous experience, but every project and approach is different.