Tiles Collision Group


I have been trying to find a solution for this for days.
From the Phaser 3 docs:

setCollisionFromCollisionGroup( [collides] [, recalculateFaces])

Sets collision on the tiles within a layer by checking each tiles collision group data (typically defined in Tiled within the tileset collision editor). If any objects are found within a tiles collision group, the tile’s colliding information will be set. The collides parameter controls if collision will be enabled (true) or disabled (false).

Please could someone tell me how to define the collision group of a tile? Or at least point me in the right direction?
Is it defined as a custom property? And if so how do you call it? I tried everything but with no luck

I tried and tried and scouted the internet for days but with no success.
Many thanks in advance!

Hey @Giovanni_Delacqua, welcome to the Tiled forums!

The “collision group” here is referring to the Tile Collision Editor within Tiled, rather than a custom property.

Hello @bjorn, thanks so much for answering me!

I did read the Tiled docs regarding the Tile Collision Editor many times.
I’m a little confused because, the Phaser docs say " collision group data (typically defined in Tiled within the tileset collision editor)". Doesn’t this mean that somehow I have to define the groups using the Tile Collision Editor in some way?

Please just check my configuration:

I’m console-logging the tileset object, and then calling some methods on it.
The getTileProperties gives me back all the custom properties as set in the Tile Collision Editor, but when I call the getTileCollisionGroup on the same tile it returns null.

Regarding this last method the Phaser docs say:


“Get a tile’s collision group that is stored in the Tileset. Returns null if tile index is not contained in this Tileset. This is typically defined within Tiled’s tileset collision editor.”

In the picture you can see that I’m using “204” as tileIndex. Passing it in the getTileProperties method returns the custom properties of the tile, but the I get Null when trying to see the tile collision group with the getTileCollisionGroup method.

I’m real sorry for the lengthy post, but I would really appreciate the help, as I’m sure would many others that are trying to understand the same thing.
Many thanks!

As far as I can see in your first screenshot, you have not created any collision shapes on the tile in the Tile Collision Editor. As such I’m not surprised to see null as the result of getTileCollisionGroup.

Please try adding a rectangle or polygon in the Tile Collision Editor.

I see, thanks so much for the quick answer!

You are right…adding one or more collision shapes indeed automatically created group data for that tile.

I guess what threw me off was the assumption that you could define different collision groups for different tiles within the same tileset, while the groups in the phaser docs refer to different collision shapes on the same tile.

Many thanks for the clarification and thanks for this great tool!

Alright, so indeed you can define different collision groups for different tiles. Each tile has its own collision group, and each collision group can contain multiple collision shapes. I hope all is clear now. :slight_smile:

You’re welcome and have fun creating your game!