I’m making a factory game. It needs to keep chunks running while game is running.
But it used more than 150 MB memory only to keep 121 chunks running and those chunks only have floors.
I think this is weird for a factory game.
There’s my structure for World and Chunk:
| |- Chunk
| | |- TileMap(floors)
| | |- Entities(but now it's empty)
| | |- Tiles(stored in a dictionary with Vector2i as index)
| | ...
How do i improve it for less memory usage?
If you are using the TileMap class many times, that may be the main source of bloat. It holds a lot of data that you may not need. Check if removing that significantly reduces the memory usage. If so, you could make a smaller implementation of it using just your Tiles array and the atlas texture. This means no terrain autoplace support, no navigation automation, no coordinate conversion facilities, etc, etc, but may be much leaner.
That said, 150Mb is not that much memory for a game. Consider making a more complex example as a benchmark because you may find that it doesn’t grow exponentially (maybe).
Also, on the other hand, you may be storing duplicated data on you Tiles arrays. TileMap uses tile references to avoid data duplication, but if you’re naively holding the full actual data of each tile multiple times, your dictionary might be the issue.
I solved it by use a shared Tile object.
it used about 40 MB memory.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.