Tilemap collision shape doesn't update w/ set_tile

Is this something that can be done or is planned? It would be very convenient feature. For instance, if the player completes some quest a pathway could be opened by removing wall tiles from the tilemap which then could be passed through by the player. Or, is there some way to call an update routine on the collision object to use the tilemap in memory vs the one loaded from disk?

EDIT: If not a way to directly modify, how would I go about constructing my own collision shape from the tilemap data after map editing? The collision resolution features for tiles are very convenient (being able to create a mask for each tile or auto-determining the mask based on alpha value) so I would like to use this somehow.

Collision shapes should be updating as you edit the tiles. I know I’ve tested it in the past and it worked. Can you try to make a minimal example where it does not?

What I do typically in games like this is use external editor like Tiled and associate entities with collections to spawn with factories for various elements in the scene. So a breakable wall might not be tiles but an collection with objects in it and a script potentially.

I have a tilemap in my game and I tried adding logic such as:

for y=14,18 do
    tilemap.set_tile("#map", "walls", 3, y, 0)
end

This removes the walls from the tilemap and I can see the background tiles in the layer beneath (which don’t collide with the player) however, I can’t walk through this zone it still collides as if the walls are still there.

I have thought about what you said for having a destructable object added separately, however, what if I want to generate a room layout randomly and add those tiles into an existing tilemap at runtime? This would avoid having to (and I’m not sure this is even possible) construct that room as a tilemap and somehow position it within the parent tilemap.

If you are randomly generating levels you can still assign entities to cells and spawn them at the appropriate positions.

I’ll quickly make a sample and see if it’s working like it used to.

Thanks, but don’t worry. I already have this type of system in place for spawning enemies from the tilemap and then removing the spawner tile after spawn. However I want to be able to add/remove walls from the tilemap and have that reflect in the collision object. But it seems that the collision object if set to tilemap only generates the hull when the game first loads the collection and it never updates… It would be nice to have some kind of function call to let the engine know the tilemap is done updating a bunch of tiles and to regenerate the collision object.

This is what I’m making a sample for btw :slight_smile:

Here’s a screenshot to illustrate. I can try to make a simple project later to demo if it will help:

As shown: the before image is how the map loads from within the collection factory using the tilemap data. After, is shown when the tiles are removed. The collisions however stay the same as when the tilemap was first loaded regardless of the wall tiles showing.

TilemapChangeCollision.zip (5.0 KB)

It does work as expected, but it’s possible I don’t understand the actual problem.

I’ll test loading from a factory next.

Don’t forget that collection proxies have different physics worlds if that’s possibly related.

My game is setup similarly and I’m removing the walls much the same as in the example you showed. However, my player is created in a factory which exists in a “main” collection, and the level itself is created by a collection factory which is part of main. Then, the level script which is part of the tilemap-related object destroys the walls. There are no collision issues with this setup until I modify the tilemap using the script… Not quite sure what I’m doing wrong I’ll have to try some other things.

Also works as collection factory, so you will need to post an example of it not working.

TilemapChangeCollisionCollectionFactory.zip (5.8 KB)

Hmm, I recreated the same structure as in my game but I don’t see any problem with removing tiles and having the collisions register… Not quite sure why it won’t work in my game. I’d share it but I’m planning on commercializing at some point and I have a ton of non-shareable assets in my project that I’d have to remove.

You can send it privately to @britzl to check out. If there is a genuine problem they will want to have a sample of it.

1 Like

I think this might be some kind of bug. If I bind a hotkey to send a message to the level script to transform the level via set_tile then the collision object updates properly. I tried simply having the main.script send a message once the level indicates it’s been loaded to send another message back to do this, but the collision object bug returns. It seems like I need to wait so many frames after the level loads before I can call set_tile and have the physics object update properly. Not sure what’s going on here.

EDIT: I figured it out. If I make changes to the level once the first update loop in the level.script executes, then it seems safe to transform the level geometry. If I do anything prior to the first update loop only visually the tiles change and adding in new walls works, but removing walls which were previously there leaves the collision mask in place.

That sounds like a bug, could you make a minimal reproducible sample?

Sure I’ll modify the project you sent over in a bit to reproduce, it shouldn’t be too difficult. Need to finish productivity goals for the day first. Making pretty good progress, the engine is definitely good I am able to work much faster than without for sure :slight_smile:

1 Like

Here’s an example of the tilemap collisions not behaving as expected:

tilemap-collision-bug.zip (105.9 KB)

Move the player (kinematic object) with arrow keys. Debug physics show collision with removed walls (during init). Ones that are removed within the timer.delay function register collisions properly. This shows that tileset.set_tile must be deferred until later. I’ve determined from my own testing that the first update loop must execute before the collision shape is properly updated (for my own game.)

Indeed. Please create an issue on GitHub and attach the repro project.

This may be the same issue:

Forum thread:

1 Like