I’m trying to make an infinite dynamic map generation. I’m using cellular automata to generate single chunks (using tilemaps) and place them with a factory. The problem is that the game freezes every time a new chunk is created. I made some investigation on the cause of the problem and I found out that the problem is not the algorithm that generates the map, but it’s the method that I use to spawn a tilemap and setting the tiles to the values that gives the algorithm. Now IDK how can I optimize this to fix the freezes. Any suggestions?
Hmm, I see the words “infinite”, “dynamic”, and “freezes”, and somehow I am not surprised! But jokes aside, you will need to share the relevant parts of your code for us to help you with optimization. If we have no idea what your method is, it’s rather hard to say what could be improved with it.
Making a Terraria-like, I am soon going to be encountering the question of how I create a dynamic map. Mine is not infinite thought…but I have figured out a way to generate a world. If you have trouble with chunks freezing the game, try reducing the size. If you think about it, you only really “need” to generate chunks when the player is getting close to a new chunk.
What do you have so far?
You do not have to use tiles you can use Game Objects for this kind of thing. Then create/destroy as you scroll around the world. I’ve used this method before and it worked fine.
Like @ross.grams says we need more information about what you are actually doing to help. If you can make a minimal example project where you see the issue that would be the best way.
So, after other investigations, I noticed that I forgot to optimize some heavy code before showing the tilemap chunk. Now the freeze is much less than before. Now the problem is cellular automata that it’s not light enough to be generated in runtime without freezing the game, so now I really need to find a good alternative.
The idea of the game is a platformer set in space with a character that can jump through objects in space (asteroids mainly). The game should evolve vertically. The method that I am using now is having a factory that generates a chunk gameobject that contains a tilemap, a collisionobject and a script. A map object checks if the player exceeds a limit and if it does, generates a new chunk using cellular automata (for now) and creates a new chunk object. The new chunk object iterates over the generated map and sets the tiles of the tilemap from the tiles of the map.