Sorry for the clickbait title, but if you’re using tilemaps in your projects, or you’ve ever had the editor crash with an out-of-memory error - you really should read this. TL;DR at the end.
The problem
You may have noticed that tilemaps remember their previous size. That kinda makes sense: if you shrink a tilemap and later make it bigger again, the tiles aren’t erased - they’re still there.
But now imagine these scenarios:
- You have a large open-world layout, say 20,000×20,000 pixels, and you add a new Tilemap object. By default, the tilemap takes up the entire layout, so its size becomes 20,000×20,000. You then resize it to what you actually need - say 300×200 - and think nothing of it.
- You have a fairly large tilemap, maybe 3200×3200, and you want to reduce the tile size from 32 px to 16 px. But instead of typing 16×16, you accidentally enter 1×1. Oops. You notice the mistake, change it to 16×16, and move on. No harm done, right?
Wrong.
In both cases, the tilemap will now forever remember its maximum size.
Tilemap #1 is now 20,000 / 32 = 625 × 625 tiles
Tilemap #2 is a staggering 3200 × 3200 tiles - tiles, not pixels!
Why is this bad?
Browsers have a hard memory limit per tab. In Chromium-based browsers it’s about 4 GB. That means the Construct 3 editor - including all its modules and your loaded project - must fit within that limit.
Now let’s see how much memory our “rogue” tilemaps consume:
A tiny tilemap #1 with a visible size of 300×200 px takes 15 MB of RAM.
And that’s per instance. If you copy that tilemap to 100 layouts, that’s 1.5 GB - over a third of the total allowed memory.
Tilemap #2 uses 410 MB. That’s 10% of the entire memory budget. Duplicate it once? Boom - another 410 MB gone.
It doesn’t matter if the instances are on different layouts — the editor loads all tilemaps from all layouts into memory.
And eventually this happens:
There is a bit of good news: it seems that invisible areas that are completely empty (tileID = -1) don’t get loaded into memory. Unfortunately, the moment you use the Bucket tool, those areas get filled with tiles — and now they do count.
Real-life implications
“But those are unrealistic scenarios” you might say.
Ha. Let me tell you a sad story.
While working on our game, I’ve been dealing with random “Out of memory” crashes for years. I upgraded RAM multiple times, tried every Chrome flag imaginable, switched to Edge and Brave — nothing helped.
Our project sits at around 3.5 GB of memory usage, right on the edge. Any sudden spike (for example, running a big search) can push it past 4 GB and crash the tab.
We use tilemaps a lot. Just one example: we have 30 dungeons, each built from lots of small tilemaps (rooms). Each tilemap’s visible size is 40 × 22 tiles, but their maximum (invisible) size was 335 × 138.
I honestly don’t remember how this happened. Maybe originally we planned one big tilemap per dungeon and later resized it down to single rooms. But Construct remembered the original size forever.
I’ll spare you the math, but that’s ~20 million invisible dungeon tiles just sitting in memory, wasting RAM and CPU.
Yesterday I ran a script that updated all tilemaps across all layouts.
It processed 560 tilemaps and removed 98796127 tiles. 99 MILLION. Freeing almost 3 GB of RAM.
No more crashes. And the editor runs a lot smoother.
Important note: this applies only to the editor. In exported projects, invisible tiles don’t matter nearly as much — they will probably increase memory usage and save size, but won’t crash your game.
What this means for you
Check your tilemaps, people.
Here is the script that automatically resizes tilemaps to their visible size. (requires NWjs for batch mode). Use it at your own risk, and please back up your project first.
EDIT: R0J0hound made a much better version, use that instead.
TL;DR
Tilemaps in Construct remember their maximum size, even after you resize them. This means a tiny-looking tilemap can secretly contain millions of invisible tiles, eating huge amounts of RAM in the editor. Since browsers have a ~4 GB memory limit per tab, this can cause random “Out of memory” crashes. Check your tilemaps and make sure their max size matches what you actually use.