Merge Instantiated GameObjects during Runtime

I generated a Maze with instances of a GameObject Cube. I don’t have the rigidbody component on the cubes, but they still drop the framerate every few seconds. Now my question is, how can I combine these Instances into one Mesh during runtime? I found this, but I don’t understand it:Mesg.Combine Meshes

I’m using a DFS algorithm that removes walls while walking through the maze and then after generating it renders the cubes in the Start Method. I’m using C# ONLY and am also not very experienced, since I started with unity a week ago.

PS. I don’t want to change my Maze generation algorithm and I can’t make it smaller.

You could do this:

  • Create your “logic” maze as you do now.
  • Create a plane that will serve as the floor of the maze.
  • Create the cubes that make the wall blocks as you do now, but make them children of the plane (the floor). You can use something like cube.transform.parent = floor.transform; With this, you will have one single object, the floor, from which all wall blocks “hang” in the hierarchy.
  • Add the example script in the link you posted to the plane object.

On start, the plane will combine all children wall blocks into a single mesh.