Rumble Crumble Logo

Devlog 5

Ice Crystal Bug


The Problem

Ice Crystals are a fairly recent addition to the game, they are a powerup that once collected will burst and turn nearby blocks into ice, allowing you to dig all the blocks as if they were one.

These worked absolutely fine on my (Windows) machine, both inside the unity editor and when playing in the built executable. However, strangely enough, on Gryph’s Mac, the ice crystal would burst and the tiles would update to be the correct icy version, but those tiles would have no collision at all!

This was so annoying to actually reproduce and fix because his mac is not powerful enough to get everything setup with the whole unity editor to actually debug. On top of this, no exceptions were being thrown at all, as I’ve got the unity cloud diagnostics set up and wasn’t getting any notifications through that. So having it debuggable on his machine probably wouldn’t have helped in the first place!

Basically this meant I had to resort to just trying things and sending him builds to test, this obviously is not ideal and I’ve just been putting it off for so long - but now that we’re getting closer to release I really didn’t want to have this bug around for mac users. I mean, at least it’s not completely game-breaking right?

The Solution

I pretty much started at the source, and thought, well where does it stop working. It stops working after the tile has already changed sprites, and that happens during a Unity function call - Tilemap.SetTile()

TransformTiles The TransformTile function, which gets called for each tile that needs to turn to ice.

This whole function runs without fail on both mac and windows, I even tried removing everything other than the SetTile call, just to see if it was some of the other code that I added - to no avail.

So that means it must be something in the editor right?

Well, after a bit of digging around and searching through all the rule tile assets, I noticed that there is a “Default Collider”, and a “Collider” option on the rule tile and each sprite of the rule tile. Now since this issue is regarding collisions, I thought that makes the most sense to look into.

There was nothing conclusive about that though, some of the tiles were set to Sprite and some of the tiles were set to Grid. Ice was set to Grid default collision mode, and each of the rules within it were set to Sprite - a bit strange but not different to some of the other rule tiles either.

This did make me wonder though, as the collision on Gryph’s mac did actually work for single ice tiles, so if there weren’t any conjoining ice tiles you wouldn’t be able to walk through that single tile. So clearly the Grid collision mode was working as the default collision mode gets activated when it’s using the default sprite, which is the single tile on its own!

I confirmed this with Gryph by sending a build over where all the ice rules were set to Grid and lo and behold it worked!

So why wasn’t sprite mode working for ice but it was for others, well it turns out there is a single checkbox on each sprite (not the tile asset) called “Generate Physics Shape” and this wasn’t active on the ice sprites, but it was for all the others that were in sprite mode!

Not sure at all why this worked on windows but not on mac, maybe the default collider on the rule tile is the one that’s used for all collisions on windows but not mac? Maybe it’s because they are added at runtime and the “rule” for the tile joining changes, and mac correctly updates the collision but windows doesn’t?

Whatever it is I’m very glad it’s fixed now, and I’ve also changed all the tiles to just use the grid collision, and disabled generating their physics shapes, as it’s all grid based anyway, so I’m sure this will help a bit with performance anyway.