In the game that i am trying to make i essentially generate an infinitely generating maze that has no dead ends and each corridor is of the same width.

i have successfully managed to create this system however once i have created the floor tiles on which you are supposed to walk on i need to generate some walls. these walls surround the floor tiles preventing you from leaving the floor tiles. the system that i have for making these walls right now is very inefficient and redundant so, i would like to find a better way of doing so.

my current system for making these walls:

first, a Floor Builder lays out all the required floor tiles then i have a wall builder game object with numerous empty games objects in a single row that each have a script attached to them that checks if there is a collision on their current tile. if there is a floor tile nothing happens else a wall game object is spawned which is essentially a 1x1x1 cube that has a collider attached to it. once all the checks have been done the parent game object is move 1 tile upwards and the process repeats itself.

once the player is out of range of the walls that are left behind a garbage cleaner game object just destroyed them.

this system can be improved in terms of code by using arrays instead of multiple game objects however that would still not improve the performance since the cause of the performance drop on slower devices it that a lot of game objects have to be spawned and tracked. the whole system is very inefficient and produces about 100 to 500 game objects which are destroyed later on.

i have attached a picture to give an idea of how the system works ignore the cubes and other entities. a working representation of my current system

there are also other solutions i have looked into and made

Single line Builder:

basically, at the boundary, i put a single game object that starts and stops when a player is nearby or not it goes from right to left checking each 1 unit of space for a floor tile and spawning a wall if there isn't. this was a much more efficient but slow solution which i later improved on.

Smart Single line Builder:

its mostly the same as the previous one however once it is in an empty spot it fires a raycast on its left side and when that ray hits a floor tile it uses the information obtained with its current coordinates to make a single row big wall instead of multiple walls this system worked much better but was still so slow that the player is able to run faster than the system can make walls.

The kind of system that i would like to have: a simple quad that sits below the floor tiles and moves along with the player. the quad is essentially pulled upwards in places where there isnt a floor tile. i have no idea how to make something like this.

  • \$\begingroup\$ Don't destroy your walls and stuff, disable them and store a reference somewhere. When you need a new wall, use stored walls first before creating new ones. As you are using equaly sized wall segments, that should work very well. (Keywords: Caching, Object pooling) \$\endgroup\$ Commented Aug 30, 2019 at 21:05
  • \$\begingroup\$ I am not sure i understand your solution. in my game the wall stuff that has been instantiated once will no longer need to be seen its a type of endless runner so the player doesn't need to go back to a previous area. i am sorry if i have misunderstood your opinion. \$\endgroup\$ Commented Aug 31, 2019 at 0:14
  • \$\begingroup\$ Nevermind i actually researched a bit about object pooling and i now understand what you meant to say. however, i don't think that it would fully solve my problem since the problem is not with over instantiating and destroying but rather with keep track of that many objects at once and adjusting for their real-time lighting \$\endgroup\$ Commented Aug 31, 2019 at 1:07
  • \$\begingroup\$ Have you profiled where the performance bottleneck actually is? Which method takes to much time? Thinking about bottlenecks is good, but profiling gives you actual numbers to work with. \$\endgroup\$ Commented Aug 31, 2019 at 9:37
  • \$\begingroup\$ yes i have profiled the game. as soon as the actual game starts there is a huge spike in FPS which is although unnoticeable in my PC is a 1 to 3 seconds long pause in my phone. the bulk of my performance is consumed by rendering scripts and physics in exactly that order from highest to lowest. since my wall building mechanism uses heavy raycasting there are at a time at least 500 instances of raycasts during the starting few seconds of the game and at least 74+ wall builder script instances during normal gameplay after initialization. i can hardly get a stable 15 FPS on my phone \$\endgroup\$ Commented Aug 31, 2019 at 22:16


You must log in to answer this question.

Browse other questions tagged .