Creating tilemaps through factories does not update collision for programmatically changed tiles

Hello,

I have a tilemap with a script which dynamically creates passages in walls by using tilemap.set_tile.

This is the original tilemap:

original

This is the same area when the script creates a passage in the wall:

(screenshot from when the tilemap object was added manually to the scene)

manually

However I’m having a problem when creating the tilemap objects through an object factory.
As you can see in the following screenshot, the tiles are updated correctly by the script, but the collision does not get updated.

(screenshot from when the tilemap object was created by a factory)

factory

What is also strange is that as you can see in the screenshot, new collision areas were created correctly, however they weren’t removed from where tiles were removed.


For now, as a workaround, I will inverse my generation approach and have the script close holes which are open by default, since apparently collision areas can be added but not removed?

Or tell me if there’s a better way to achieve what I’m trying to do :slight_smile:

Thanks!

PS: Floor tiles are being randomized, don’t think that these are different tilemaps :stuck_out_tongue:

1 Like

When modifying the tilemap, are you changing the correct layer? If you’re adding the new tiles in a different one, the original layer would remain hidden underneath, including the collision objects.

1 Like

Ah, clever, that may indeed be the problem! Please confirm @Haath if this was the case.

1 Like

Hey, @britzl

Yes I’m definitely editing the correct layer. When I add the tilemap to the scene manually via “Add Game Object File” (screenshot 2) everything works perfectly and the collisions are set up correctly. It is only when I create the exact same object using a factory (screenshot 3) that this issue appears.

Would it be possible for you to create a minimal example showing the problem?

Now that I think about it, I ran into something like this when I was working on Jetbot Jumble. I don’t remember details, but I think I figured out why it was happening, though it still meant I had to make some workaround.

Looking at my commit messages, I don’t think I have a version with the bug present, but I could look at the code tomorrow and maybe remember what exactly happened.

1 Like

Of course!

Will @ you here with it sometime next week when I’m done with this game jam I’m trying to create a submission for :slight_smile:

2 Likes

I looked at the code, but I can’t figure out what was my original approach that lead to the bug (if it even was the same issue). I played around with it a bit, but I couldn’t reproduce it.

1 Like

Best of luck to you!

2 Likes