- Home /
Colliders vs Callbacks: Which is better for performance in my case?
Currently, I have a Tetris-like puzzle game with multiple pieces that may fall on top of each other and form "clusters" of chained pieces.
However, I'm planning on redoing all coding from scratch because the game feels very sluggish on mobile once block stacks start rising a lot. This is specially true when they're moving (chunks of blocks may move depending on the input) and when they're merging with other chunks, since it involves lots of for-each. This original code also relied upon Images inside a Canvas to render in-game art, which is not reccomended by Unity themselves, so I'm starting again using Sprites in pure 2D Scene.
My biggest doubt, however, is how I should handle block collision and movement in this new engine. I can think in two distinct ways, but I don't know which one would be the most responsible:
Case 1:
Use block instances with BoxCollider2D to detect their own collision with blocks either below or above them, and act accordingly. Last time I tried this (years ago), I had a terrible problem where blocks would suddenly feel squishy and soft when piled on top of one another. Using Kinect settings didn't help it since it disabled collisions, and increasing Physics2D timesteps made it less apparent even though it was visibly still there. Plus, changing Physics2D settings in a mobile environment is a bad idea.
Case 2:
Make blocks report their own position to a general "Block Movement Manager" that knows the coordinates of all blocks through Update callbacks. Once the Manager detects a block is entering another one's height in pixels/Unity units, it'd trigger a Collision method and act accordingly. Last time I tried this (less than a year ago) I had another terrible problem where blocks would visibly sink for a single frame inside other blocks before the Collision method triggered and re-anchored then in the correct grid coordinates. I tried LateUpdate, Update, FixedUpdate but nothing seems to change that, so I gave up completely. However, this case removes any Physics and Collision elements from the logic, which to me seems to be much faster and streamlined.
Which one of those would probably work better in mobile, and why? I need to decide between one of those before starting this project from scratch again (third time now) and I don't have a clue how I should proceed.
I'm not sure you need physics or collisions at all. How unique of a tetris game are you making? Is it the typical blocky movement where every square is within a grid?