Game Dev: Unity/C# — What is the Flyweight Pattern?
<p>The flyweight pattern is mainly used as a performance optimization technique. It typically comes in handy when dealing with large amounts of data. The term “large amounts” will be relative to your general performance goals.</p>
<p><img alt="" src="https://miro.medium.com/v2/resize:fit:493/1*B3-9YdMzYYLjhywxluZH9g.png" style="height:315px; width:493px" /></p>
<p>Either way this is definitely a useful pattern to learn for when you do need it.</p>
<p><img alt="" src="https://miro.medium.com/v2/resize:fit:319/1*4f_EJ3mXKr0HQSu2QEjCXw.png" style="height:102px; width:319px" /></p>
<p>Let’s start with an example. Let’s say you have an Enemy script that is on 12 enemies in your game. The enemy script has a health variable, a max health variable, and damage variable. That means there are technically 12 instances of these 3 variables existing across all the enemies. In most cases, so what? But, lets say you have 10,000 enemies existing at once. Well that means each variables exists 10,000 times. That could need some optimization depending on your performance goals.</p>
<p><a href="https://blog.devgenius.io/game-dev-unity-c-what-is-the-flyweight-pattern-ec58b75b13fa"><strong>Website</strong></a></p>