How can I use the physic shape of the sprites as colliders for my tilemap?

Hey guys,

I am completely new to Unity and Game Development and try to use a tilemap to build my game on.

Because the presets for the Tilemap Collidor 2D don’t fit to my wishes I gave each sprite of the tilemap its own physic shape in the Sprite Editor. Now I want to use them as colliders, but I cannot change the Material form “None” to “Sprite” in the Inspector for the tilemap.
It just opens a window, where I cannot slect anything. It just calls “None”

Do you have any ideas how I can use my own physic shapes for my Tile Colliders.

I apologize for my bad English and would be very thankful if someone could help me with my problem =)

Hey @Turtleclasher , it sounds like you have already done the first few steps correctly by drawing out your custom Physics Outline in the Sprite Editor’s Custom Physics Shape module.

7579597--939373--Sprite Editor Custom Physics Shape.png

You wouldn’t need to add any Physics Material in your Tilemap Collider 2D component to make your Physics Shape show up.

But you do need to make sure that your tile assets’ Collider Type is set to Sprite and not Grid (nor None). So that the Tilemap Collider will take the Physics Shape you drew and not the default Grid i.e. square if it’s a Rect Grid.

7579597--939376--Tile Asset.png

Hope this helps! :slight_smile:

True!

After the steps above, for my case, it turns out that I also needed to right-click my TilemapCollider2D and Reset it.
Now it works :slight_smile:

3 Likes

That seems like a workaround to the real problem. I’m also facing something very similar to this, where the tilemap collider instance only “refreshes” after I try any of these:

  • Reopen the scene
  • Enter/Exit Playmode
  • Manually reset the component

Ideally, I do not want to deal with a manual fix for this like the 3 solutions above. It would be neat if there might be a way to simply force-regenerate the collider, but there doesn’t seem to be any API that directly does this. If anyone knows of a way to regenerate the tilemap collider, that would be really awesome for me to know about; My goal is to refresh a tilemap collider for an automated process that generates tiles. But currently, the tilemap colliders don’t update their shape even if I update a sprite physics shape, which could appear strongly misleading.

2 Likes

I can confirm this is true. You need to replace or reset the Tilemap Collider 2D component in order to use the Physics Shape as colliders.

So you’re painting the tilemap and the colliders are not producing the correct shape? They’re just the… grid collider? What version is this?

An editor shortcut could be a temporary fix. Does this work?

        [MenuItem("MyShortcuts/FixTilemaps #&c")] // shift+alt+c
        public static void FixTilemaps(MenuCommand _)
        {
            foreach (Tilemap item in GameObject.FindObjectsOfType<Tilemap>(true))
                item.RefreshAllTiles(); // this step might be unnecessary but just in case...

            foreach (TilemapCollider2D item in GameObject.FindObjectsOfType<TilemapCollider2D>(true))
                item.ProcessTilemapChanges();
        }

To update on this since, I have used the function:
Unsupported.SmartReset(collider);

It makes the collider refresh, albeit at the cost of losing custom component information in the collider.
It’s my workaround, but it’s worked for my needs and refreshing many colliders at once with little editor performance costs.

not working :\

You’d need to provide more information about your workflow.

Though it should and does work. I know that in some versions this was bugged in the aseprite importer. You’ll have to update it manually most likely.