Game Design Pattern: Flyweight- Game Dev Series 140

S.J. Jason Liu
2 min readOct 15, 2021

Objective: short introduce the Flyweight game design pattern.

Flyweight

In this tutorial, I would introduce another game design pattern, which is the easiest one.
When we create an object, let’s say, a sword.

A sword should be with the following basic data:

When creating a sword with this script attached, it means these data would processed once. However, if you create a thousand swords, even more, ten thousand swords, these data of a sword would processed ten thousand times.

My Mac is screaming for processing these swords!

You might notice that there are some data that would be the same on each sword: main part, sub part, and type.
These are the data that we could make these sword sharing, not just processing every time a sword generate.
This is also the concept of Flyweight game design pattern.

To implement this design pattern, we just make those data that shared the same information as “static”.

That way when a sword is generated, these static data would be stored in the system and can easily to be implemented with other swords.
There should be less resource wasted in game processing.

--

--

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.