Optimization with Top-Down Walls

So i’m making a Top-Down Shooter game with walls, a LOT of walls in it. and since there is no built in behavior, i need to set an event where i would seperate the wall and the player whenever their collisions touch, and optimization wise, GDevelop did NOT like that… so i was wondering, is there any other way to optimize or alternatively do the wall thing??

And before ya’ll ask, YES, all walls in the game are solid.

If your walls are different, then you can make a object group that has all the different walls so then you can use seperate object on the whole group in one action

in theory you could make some sort of lookup table with the x and y positions the player can not move. that might be faster, if that skips the position calculation of the walls each frame (idk how efficient the collusion check event is).
another idea would be that you check for distance first and only check for collision of walls close to the player (could also be slower, if collision is more efficient than distance).

You could try creating an action to always move player away from walls. No condition, just the action.

I don’t know how it will work in your circumstance - it probably depends a lot on the size/amount of walls but it has gained me some performance before.

Are you using seperate two object action?

…yeah pretty much.

How many types of walls do you have

It has alllllooootttt of walls. the entire level has it.

I tried doing that, it still lagged.

You could try adding the behavior to the walls “destroy when off the screen”

Speaking of behaviors, are your walls normal “sprite” or “tiled sprite” objects, or did you use the behavior “platform” on your walls?

I think the collision and separation events are already built in to the “platform” behavior, so it might run a bit better - but then you’d have to make your character a platform character and add the action “ignore default controls” to your events.

Also, just to be thorough, what kind of system resources do you have? I think gdevelop requires 1GB ram on its own to run, plus whatever is needed for your game.

Another possibility: use an extra object to make a perimeter around a wall. For example, if you have 10 sprite objects to make up a wall, you could wrap them all in an invisible objects, for example called “wall_perimeter”, then check the collision on just the 1 wall_perimeter object instead of the 10 wall sprites.

Can you share a screenshot of your scene and the code

  1. the “destroy when off the screen” behavior PERMENANTLY deletes the object when off screen, and i can’t do that.
  2. it’s a tiled sprite.
  3. the “platform” behavior only works with, well, platformer and platformer characters, not top-down characters.
  4. i have 4GB
  5. the walls is the only solid object atm.

imagine that but to the ENTIRE map.

you could split the map in smaller parts and switch between them via scenes, think zelda 1 Rooms

The grid setup gives me an idea. Maybe you could try to limit the collision by location, like this example:


I presented 2 methods here as I don’t know which (if any) might work the best.

I generally prefer nested conditions over using “AND” as I feel it’s easier on the cpu than the AND condition: rather than testing all the conditions at once, it’ll test the easier conditions first then quit if it can before testing the harder conditions.

You need to add a condition: if player is in collision with wall : separate player from wall

I am also making a game like your and I stress tested it and found that the separate object action will make the game lag if it is used frequently, and because you don’t have a condition it is used all that time is checking to separate the objects. when I added a condition to the action it really decreased the lag and my system only has 2GB of RAM. It should run well for you

The scene

The code for collision

Stress test without conditon FPS: 8

Stress test with conditon FPS: 54

EDIT: I saw that you tried using condition before. I guess you should go back to it and add a condition. It might reduce the lag and I don’t see any other way it is creating lag. Maybe it is a problem with some other part of your code.

You can optimize a bit more, detect the walls in a short distance of your player entity and use the nearest walls for verify the collisions.

If you player entity don’t move you can also use it in a and condition for avoid to compute the collision.

The idea is simple when you don’t need something, think to disable it.

Here a shortwiki page about optimizations.

(The link of this page may change, ping me for update it)

1 Like

Is there a way to test collision with the nearest object?

There is a condition for check the distance, an and condition, and an condition for verify the collision.
Everything exist already.

1 Like

I tried it but it is not working. I think (I don’t know )the distance condition is checking the origin point of the object and the player and because I am using an tiled object the player is sometimes clipping through the walls like this