Spawning many Actors - Huge performance Hit!

Hey guys,

I am working on a Runner game like Temple Run. It will be a mobile game and I am spawning my level tiles at runtime, which already is not that great for mobile performance. But most of the time I get more than 50 FPS which I am fine with. I get micro lags as soon as a new tile is spawned, did not find a way to fix that so far ;(

So now to my question:

I want to spawn many Gold Coins within the Construction Scripts of the level tiles. Basically simple round low poly objects. No shadows. Very low poly. I am using “Add child actor component” for these pickup items. I get micro lags as soon as a new tile is spawned as mentioned above, and even worse at some parts of my level (especially parts with alot of coins) my fps drop below 30. Now I am struggling to fix this. Is it because there are too many draw calls? Are there too many actors being spawned and rendered at runtime? I am clueless.

I heard about Instancing, though I don’t really understand how it would work in my case. I also heard about pooling but same applies here, no clue how I could implement it.

Is anybody willing to help?

Have a nice day!

Push :frowning:

Still need help guys ;/

Instancing: Use a Single Instanced Component and tell it where to the transforms will be for the Copies of the Mesh. They will be all rendered in a single Draw Call. This will tell your GPU to Render this Mesh at multiple Positions instead of doing it one by one.

Pooling: Instead of Spawning and Destroying all the Time you simply Hide Objects you don´t need anymore for later use. Only Spawn new objects if there are no Hidden Objects left in your pool. This will avoid the whole Spawning and Destruction process.

That said usually Spawning a “couple” Actors at a time won´t hurt your performance. Learn about the Profiling Tools of UE4 to identify whats Bottlenecking your Performance. Once you Pinpoint what is causing trouble you can adress it with the Proper Solutions. Don´t be afraid of looking those things up there are Planty of Ressources around the Internet. Also try to Understand the Limitations of those Solutions and in what Situation you can apply them. There are reassons why we don´t use those things by default, if you use them wrong you can Hurt your Performance even further or cause Problems in a different Area. To give you a example case for the two above: If you don´t delete objects because of Pooling you keep them in Memory and thats something you got a limited amount of. Instancing will Render every Copy even if you can only see one tiny bit of it. That will put more work on the GPU but solves the Bottleneck Communicating between CPU and GPU.

In many of those cases you will find out that you usually tradeoff one thing for the other.

Good Luck and have Fun.

well, generally spawning an Actor is very fast, you should post your code on what you do in the Construction Script and the BeginPlay

http://prntscr.com/hh82mc - My standard level Tile in Viewport (Blueprint Actor)

https://prnt.sc/hh82x9 - The Construction Script

http://prntscr.com/hh83ua - Function to mark the points where blockers can spawn (fired from construction script)

http://prntscr.com/hh845g - Spawning the Blockers using “Child Actor Component” (also fired from construction script)

(coins currently are being spawned directly in construction script, tried both versions, in large portions it starts lagging)

http://prntscr.com/hh8545 - this is how I spawn new Tiles (fires when a Player leaves the old level tile)

So yea ^^ Instancing doesnt work because I am using BP Actors and not single static meshes. For Pooling I have no real idea on how to set up a logic like that. And I still get micro lags when a new level tile is being spawned. Also getting fps drops when I spawn and go through too many coins :frowning:

Anybody who is willing to help is much much appreciated. Thanks alot.

Your Actor is to Component heavy. Make a array of Transforms, Check Make 3D Widget us those instead of Arrow Components.

You can use Instances for your Blockers and Tiles. Its as simple as replacing Add Child Component with Add Instance. You can keep using Child Actors for you Coins (Im not a Fan of Child Components but thats up to you)

The Pooling part I explained in my Answer bellow.

Thanks so much for your help.

I will try it out. But I dont see a 3d widget inside my viewport eventhough I ticked it. Is this a bug? I think I have a workaround (writing down the locations of my old arrow components and then deleting them and putting in the values in the array) so it should be fine.

My Blockers and Tiles and Coins are all seperate BP’s. The only instancing node I can find is for instancing static meshes and not for actual BP Actors :frowning: so no I can not use Instances for my Blocker I guess.

And yep I appreciate that you explained pooling but I still lack a vision of how I could use it with my level system.

Anyway thanks for your help!

Anyone else with some useful tips?

Hey there,

Have you found out any usefully methods for your problem? I am very interested.

Greetz,

ERuts