I am making an Endless Runner game for mobile in Unreal similar to Subway Surfers. I am having confusing on how to spawn obstacles or a correct way to make variants of obstacles layout.
My setup:
First I made a MasterTile_BP, and then created a child BP out of it and inside I added the multiple child actors of “Obstacle_BP”. I placed different types of Obstacle_BP inside a child bp of a Tile and made multiple variants of Tile_BP and then randomly spawning from the child BPs of Tile. This is working but I think having multiple child actors inside a blueprint and then frequently spawning and destroying is heavy, especially for a mobile.
Then I tried to change my setup, I removed all child actors from Child BPs of Tile and instead added arrow components and placed them inside the variants of Tile BPs, (And also added Tags on the arrow component to tell which arrow spawns which obstacle). This setup is also working but because of spawning/destroying, it will become heavy.
What is the correct way of making obstacles/obstacle layouts? Should I randomly generate them? Or are they pre designed? If they are pre-desinged then where do I design my obstacles layout? Inside a child BP of a Tile and add them as child actors? Or how?
Hi.
Managing actors might be heavier than managing only the obstacle’s meshes. Your second setup is a nice starter, I suggest you to place empty static meshes instead of the arrows and then set the static meshes to be the obstacle you want it to be instead of creating a new actor in that spot. When the obstacle is out of the view you set the static mesh to None.
If you want to use actors instead you can just spawn them one time and then reset their position instead of destroying and respawning them.
Just remember that an actor it’s not only an object (mesh) but there is also a script in it so it is heavier then a single static mesh and at the spawn the program is initializing the entire actor.
I don’t know if you are recycling the tiles or not but I also suggest you to do it because it optimizes your game a lot.
Maybe it isn’t very clear so I will try to explain it:
This is what I think you’re doing: the runner goes forward and when a tile is behind it it gets destroyed and a new one is spawned.
This is what i mean for recycling the tiles: instead of detroy/spawn just move them.
You can apply the same concept to the obstacles.
Another optimization tip that I’d like to give you is to use a Master Material for all the meshes in your scene. If you don’t know what is a master material is a material that has a lot of parameters so you can make instances of it and modify this parameters to obtain different materials. This is great beacuse it reduces GPU Draw Calls. You just need to make one master material and the make instances of it for every object in your scene. Here it’s a very nice video that explain a nice Master Material (that I personally use in projects): Reducing Draw Calls in Unreal! [UE4/UE5/Blender]
Hope I was helpful and I’m sorry because you waited 5 days to get someone to answer you.
Have a nice day.