Voxel Game Maker

Docs Tutorials

Performance

Measure your game with the F3 panel, find the script that costs the most, and keep big worlds fast.

In the editor: Welcome ▸ Tutorials ▸ 5.1 links here; tick Done in the lesson list when you've finished.

Reading lesson · about 30 minutes · Advanced mode

What you'll make: a level that runs slowly on purpose, then the same level running fast again.

What you'll learn: how to read the F3 panel, how to find the script that takes the most time, and which settings keep big worlds fast.

Before you start: finish Capstone: your own genre game. Open any project of your own.

#1. Measure first

Press F5, then F3 in the game. The panel shows the FPS, your position and the game's values. Walk around and note the FPS in a busy spot and a quiet one. Drag the panel by its title bar; Copy puts all of it on the clipboard.

Always measure before you change anything. Guessing what is slow is usually wrong.

#2. Make it slow on purpose

Make a new script in the Scripts tab with the Event Player enters the level, add a Code node, and drag the script from the Scripts tab onto the ground in the level, as you did in Level 3. Type:

-- Far too much work, 20 times a second.
every(0.05, function()
  local total = 0
  for i = 1, 20000 do
    total = total + i % 7
  end
  watch("total", total)
end)

Play it now: press F3. The FPS drops. The panel lists the busiest scripts: how often each ran, how long it took, how many ms a second it takes now, and its busiest line.

#3. Fix it

The answer never changes, so work it out once and keep it:

local total = 0
for i = 1, 20000 do
  total = total + i % 7
end
watch("total", total)

Play it now: the script's now … ms/s falls to 0 on the busy list and the FPS comes back. Loops that run hundreds of times every frame are the usual cause of a slow game. Wait a little between checks (wait(0.25)), or do the work once.

#4. Keep big worlds fast

Open Edit ▸ Game Settings… ▸ Graphics. Four settings matter most for big worlds:

  • Draw distance stops drawing things far away, in tiles. Lichgate Depths uses 44.
  • Fade far things, Stream big worlds and Combine still objects are on by default. Leave them on.

Play it now: set Draw distance to 30, play, and compare the FPS in F3 with what you noted in step 1.

#5. Know what costs the most

Slow Faster
Code that loops over many things every frame Check every 0.25 s, or keep the result in a variable
Hundreds of enemies at once Game Settings ▸ Physics ▸ Logic rate: 30 a second
Enhanced graphics on an old PC Standard; Enhanced already falls back where it can't run
Heat haze and Black hole effects Game Settings ▸ Graphics ▸ Visual effects: Simple

Creatures far from the player already think less often, and in joined levels the far ones sleep, so you don't need to do that yourself.

#Try it yourself

  • In Edit ▸ Settings…, under Debugging, set Log slow frames to Slower than 33 ms, play your Level 4 game, and read the log (Help ▸ Open Log Folder). Fix the busiest script it names.
  • Fill a level with 200 copies of one enemy and compare the FPS with Logic rate at 60 and at 30.

#Learn more

#Next

Debugging.