Lam Cao's Blog

A Journey in Game Dev

A singleton utility for gameObjects

I use a fair number of singletons in my game projects. And I think I have written something similar the code block below for too many times now. So have you, probably.

void Awake() {
    if (instance == null)       instance = this;
    else if (instance != this)  Destroy(gameObject);

Getting tired of copy&pasting that code snippet over and over, I want to archive the same thing in just one line of code. When someone looks at my code, I want them to recognize the singleton pattern in less than half a second – “Oh hell, singleton again!”


Here goes my first game!

Today I uploaded the first public demo of Goodie Assembly on!

Goodie Assembly is a relaxing casual puzzle game. Slices appear and move toward the center from 8 different directions. As a player, you try to get 8 slices to meet at the center in order to assemble a delicious goodie (tasty food) and make sure that the slices don’t stack up too many times or the game will be over.

The target platforms are actually App Store and Google Play Store but I hope a web version will help me get players’ feedback earlier.

Link to game page:

How I learned to use State Design Pattern in my game

I learned finite state machine (FSM) in model of computation class at a university. I’ve loved it ever since. It turns out to be one of the most commonly used patterns in game development. State design pattern is not only easy to understand and implement but also very flexible. I think every game programmer should know about it, and ideally how to employ it.

I believe the best way to learn programming patterns is to apply them. In a recent game project, I learn faster by doing than reading or watching even though I enjoy good reads and tutorials from time to time. In a recent project, I had a chance to look closely at and evaluate (many of) the design choices that make FSM either very efficient or extremely painful to debug and maintain.