GDquest has started a new kickstarter campaign to create a professional tutorial for Godot, focused on 2d games.
"Learn to create 2d games with the award-winning, Open Source engine Godot 3. Free daily tutorials on Youtube during the campaign!" "You will learn to create your own top-down game inspired by Zelda"

[Answered] Tips to improve memory usage

OcreOcre Posts: 3Member
edited April 25 in 2D

Hi there !

I am currently prototyping a 2D strategy game, like "Age of Empire", with isometric hexagonal tiles, and I am facing some memory usage issue, even if the game is far from being fully featured ^^"...

I would be really grateful if you could help me to find out the cause of it :) !

I will try to describe as much as possible of my prototype, without being boring.

Here is the structure of the Map

Map (Node2D)
  |
  +---> YSort (YSort) // Just for a display correctness purpose
        |
        +-----> Hexagon1 (Area2D) // <--- (a PackedScene instance)
        |               |
        |               +-----> CollisionPolygon2D
        |               +-----> Sprite
        |
        +-----> Hexagon2
        +-----> Hexagon3
        +-----> Hexagon4
        .
        .
        .
        +----->HexagonN

As I needed each type of tile (buildings, forest, land, etc...) to handle its custom logic I wasn't able to use the built-in Tilemap, so I decided to build my own by playing with the scene system.

Each type of tiles is defined as a Scene, where I set:
1. its sprite
2. its collision shape
3. a dedicated script to handle the custom logic.

To be able to have a good image quality when zooming on the tiles, the original sprite size is (900 x 810) pixels, and I set a default scale of (0.1 x 0.1). The different sprite elements are stored in a single texture (size ~4Mo).

So, if you followed me, a map of size (10 x 10) is basically made of 100 scene instance.

With a (10 x 10) sized map, I never encountered any memory/cpu usage problems, but my goal is to have larger map, like (10 000 x 10 000)...

But I encounter memory usage issue with only a map of size (30 * 30) ! :sweat:
The debugger tells me that a (30 * 30) sized map corresponds to approximately 4500 Objects, with a memory usage of approximately 350Mo... That means each object weighs ~77Ko :dizzy:

I really doubt that Godot Engine is not able to handle 4500 objects without blowing out my memory, so I am convinced that the problem is on my side.

Again, I would be really grateful if you could help me to find out the cause this memory usage issue !

If you need any further information, do not hesitate to ask, I may not have been very clear ! :blush:

Thanks a lot in advance :smile:

Ocre

Comments

Sign In or Register to comment.