Many Dominos

This text is a written version of the video above, with future plans to incorporate graphics and figures for illustration.
As I'm working my way through the backlog of videos that were published before this website, I suggest reading the article alongside the video for a comprehensive experience.

When I was young, Domino Day was a television program where a European team of domino enthusiasts would place millions upon millions of dominos, and topple their mega creation during one magnificent evening, live on national TV.

Using DOTS

Let’s make dominos. It’s been a while since I wanted to use the new-ish DOTS technology. According to Unity, this new multithreaded framework will blow your mind with unparalleled performance. Particles, boids, flying cars, FPS coming out the wazoo, it has it all.

So naturally, I thought huh, if I want to have multiple thousands of dominos in a single scene, this should be the way to go. Mind you, these preview packages still have rough edges. Actually scratch that: they’re just 100% edges, it’s tied to an old version of Unity, and the documentation is chaotic at best.

But the performance is there.

Beginning

I started by making a simple domino with a simple shader to allow me to color each face independently. A front color, a back color, and a “top” color for the rest of it.

Now placing dominos is a long, tedious and repetitive process. Luckily the world of computers was invented precisely to handle long and tedious processes for us.

Domino Structures

Pictures & sides

The first interesting structure to make is to generate picture mosaics. This could take hours if not days when working with real life dominos, but in code, heh, that’s actually fairly simple.

Just iterate over every pixel of the image and instantiate a domino accordingly.

private void InstantiateTexture(TextureInstantiator parent)
{
    for (int i = 0; i < parent.Texture.height; i++)
    {
        for (int j = 0; j < parent.Texture.width; j++)
        {
            Vector3 position = new Vector3(j * parent.Spacing.x, parent.Height / 2f, i * parent.Spacing.y);
            Quaternion localRotation = Quaternion.Euler(0, 90, 0);

            // This will take care of instantiating the Domino prefab at the specified position / rotation / parent / color / etc.
            InstantiateDomino(parent, position, localRotation, j, i);
            // Performance isn't super important at this stage because this is an editor tool, not a runtime function
        }
    }
}

I also spawned what I’d call "sides", a series of dominos that when toppled, would in turn trigger the mosaic falling.

This wasn’t enough math so I made two more ways to spawn pictures, one that I called zigzags, and one that was on a circle.

Paths

Now in order to connect those mosaics together, I need to make paths. At first I wanted to use Sebastian Lague’s brilliant Bézier Path Creator, I’ve used it for years and it never failed me. But nowadays I try to stick with native Unity features to rely less on third-party plugins, and luckily the recent-ish 2D Spriteshape package does just what I want. The overall quality of Unity 2D features has just skyrocketed in recent years.

I can create a path, adjust the spline to my desire and then spawn a bunch of dominos along the line.

Path, check, connecting stuff, check. I just needed to add a small bridge structure to allow paths to overlap.

Sonimods

I fell down the rabbit hole of domino youtube and found another type of path called Sonimod lines. They’re like regular lines, but worse: they’re harder to put in place, certainly more prone to fall due to real world vibrations.

But they look super cool, and also due to the small displacement they’re a lot faster than regular domino lines.

Organic Shapes

Rectangular pictures are easy. But the nicest domino shapes are more organic, and for this there is no solution. At some point, if I want to make a great domino creation, I need to spend some actual time placing pieces one by one. And I think for once it’s harder in Unity than in real life. Even though real life doesn’t have copy & paste.

One useful thing I found was placing a sprite of the image I wanted to make right underneath, and then removing the sprite when I was done.

Problems

I want to mention two problems that I ran into, because game dev is all about problems, breaking them down, and solving them one by one.

Structures

The first problem I encountered was 3D structures. You see there’s a lot of super cool stuff like walls and towers and it would have been great to have them in my domino extravaganza.

However Unity is not letting me stack dominos. Dominos would sort of… slide? No matter how I configured the physics simulation, the friction, the mass, even using Havok Physics, nothing worked, so after hours of attempts and crushed hopes, I had to give up on my 3D dreams.

But somehow the sonimod lines work, so I dunno.

Performance

The second problem, performance. It all comes back to performance in the end. Despite the super performant DOTS physics and my killer CPU, having tens of thousands of dominos, each with physics enabled, was too much.

The solution I used was to disable physics for fallen dominos, and also splitting the entirety of the work in multiple chunks, or zones. While the action happens in a zone, all other zones have their physics disabled.

Conclusion

In the end fifty thousand four hundred and two dominos were toppled, and I thought this was a huge number but actually it’s… Not even close to the Guiness world record. Who has that kind of time?!

Anyway I hope you enjoyed that, I definitely did enjoy making this domino project and I can see how it could turn into an actual video game, because making domino stuff and then watching them fall is just super rewarding. Maybe it could even be a VR game, why not.

If you want real life domino videos, I cannot recommend the Hevesh5 youtube channel enough. Lily Hevesh will show you their amazing domino designs and tutorials, so definitely check it out.

Have a good one and I hope I’ll see you in the next video.

Music Credits