Data Serialization in Unity (JSON friendly)

As programming is all about what you are doing with data, I thought that it would be a good idea to speak about data serialization in Unity. Especially that now we can turn data objects into JSON with JsonUtility! ❤️

What is so special about that?

Data serialization is essential for games for a variety of reasons. Saving and loading player progress or saves, sending and receiving data from a server, and in general converting data to and from a text or files. ?

Continue reading “Data Serialization in Unity (JSON friendly)”

Singleton in Unity – Love or hate?

Those who know me, know that I have a rough relationship with the Singleton Design Pattern. Mostly I don’t like using it very often or even at all. This approach has a lot of benefits, starting with cleaner code architecture, less coupling, and in general fewer problems. ?

When to use it?

So when you would implement singleton? When you would like to have only one instance of a specific object. Example of what could be a custom resource manager where you store or load files that you downloaded from the web or any other data storage.

Continue reading “Singleton in Unity – Love or hate?”

How to implement Object Pooling in Unity

Object pooling is one of the easiest forms of optimization in Unity. Just recently we implemented the Factory Design Pattern which is related to today’s subject.

Object Pooling?

Let’s begin by explaining what Object Pooling is. So this is an optimization practice which is based on instance reusability. In Factory, we created a new instance of prefab, and later we destroyed it which is not an issue when we want to create just a few instances.

Problems start arriving when we create a lot of new instances, for example when shooting bullets from a gun, or we spawn a lot of special effects.

Continue reading “How to implement Object Pooling in Unity”

Handling UI with State Machine in Unity

One of my favorite use of State Machine design pattern is using states as different controllers of a game or an app. And today I’m going to present to you how you can implement such a thing in your Unity project! ?

As previously on AI subject with State Machine, we won’t change the implementation of State Machine and Base State scripts. They are staying the same. Maybe besides one reference and function call… ?

Continue reading “Handling UI with State Machine in Unity”