So lets say u have a basic game where u are moving and u constantly need to instantiate new objects what is the best way to perform that so u get the best performance. I don’t want the screen to slowdown or anything while the new objects are spawning. I’am aware that the spawning of new objects should be out of the view range. I’am not an expert at coding so if there is a simple way that is good enough I will take it.

It doesn’t matter if you instantiate objects off screen or within view, the result is the same: bad performance. What you want to do is create all objects at the start any while the game runs you never want to create / instantiate or destroy any of those objects. Just re-use them. Once a piece of way / obstacles / … are behind the camera they aren’t needed anymore. At this point you can just keep them behind the camera until you need such a piece / object again. Then you can just move it ahead at the right position. That’s what pretty much all endless runner games do.

I would even recommend to not deactivate / activate the objects all the time. This is also bad for performance. It’s better to just keep them as they are behind the camera. That way you get zero impact due to “spawning” new elements.

Of course you want to keep track of the objects you have available. For this you usually just put the references in one or multiple Lists. Of course you have to create “enough” instances but not too much. If you have different road pieces you usually have more common ones and some special pieces which should only occure from time to time. The common ones of course are used more often so you should have more of them available. It’s up to you how you want to handle the building of the road. You could have all spare pieces in a single List, shuffle the list and just put the pieces out one by one. When you “use” a piece you remove it from the spare list and put it into a “inUse” list. Once an inUse piece goes off screen you put it back into the spare parts list.