Top 5 Unity Game Development Concepts to Memorize ASAP
There are core tenets of Unity currently, that you should get to know before you become a professional game developer
Are you looking to quit your job and begin a new career as a Unity Developer, either as an independent studio or for an established game studio? If so — congratulations! I hope you have mustered up your resolve and perseverence. Now, onto the nitty-gritty.
In order to fully understand game development with Unity, you need to have the basics in your toolbelt. Unity development with C# has its share of quirks, so be sure to have a strong foundation in the basics of coding. This guide assumes you already know about:
- Basic syntax, variable declaration, and primitive data types
- Conditional logic and equivalency / mathematical operators
- Loops, arrays, and methods
With the absolute basics out of the way, let’s discuss some of the more involved programming principles you will need to know and understand in order to be a successful Unity game developer. While we will review these important topics at a high level, it's vital that you follow up with additional research and practice to get a full grasp on them. Without further ado, let’s get into it!
If you have opened Unity and messed around for a little bit, you will realize that the two core elements are GameObjects and Components. A GameObject is an object that lives in your scene — it can be a Cube, or a Canvas, or an Event Manager. A GameObject is in fact only defined by its Components, think of it more as a container for Components.
Components are the building blocks that define a GameObject. A Cube, for example, has a Transform component with position, rotation, and scale. These help Unity to render the Cube in the Scene. The Camera, Audio System, Renderers, Scripts, and more are all components attached to GameObjects. Note — scripts are components. With this in mind, you should already be thinking about how your codebase will be structured to work best with this system.
The traditional Object Oriented approached to developing scripts will not strictly work here. That is not the say OOP is out the window, but you need to think of scripts more as Components of a GameObject. See the below diagram for comparison. Its best to consider scripts as components that can be applied to many different GameObjects, if need be.
Component-base design is important, but don’t get ahead of yourself. There is still a need for good old-fashioned OOP knowledge when working with Unity. This includes Data Types:
As well as understanding the concept of Class-based design:
- Abstract class
- Generic Typing
- … and more
Let’s say you make a Projectile class. That’s all fine and good, now once you introduce fireballs, lightning strikes, and hurled stones, having an inheritance structure could definitely help. Also, OOP will always be relevant and important to learn and understand for future programming endeavors.
How to Build an Audience for your Indie Game
If you work hard making a game, do your best to get people to play it too!
Everything About the Update Loop
Don’t let this header fool you — get to know the entire Script Lifecycle, not just the Update loop. There is a preset order to all events in the lifecycle, and understanding them will save you a lot of headaches down the line.
But for brevity’s sake, we are going to focus on the Update loop. If you have spent some time with Unity, you at least know about Fixed Update, Update, and Late Update. Fixed Update is called independent of frame rate, making it more reliable for Physics calls. Update is called once per frame and is beholden to how well your computer runs your game — it is common to put I/O in the Update loop. Late Update is called at the same frequency as Update but is only called after Update has completely finished. A good use case for Late Update is a late-following 3rd person camera.
It is vital that you follow the above instructions, and use all Update functions sparingly. Since Updates are called once per frame, it is called very very often, and games with a lot of execution in the Update loop are destined to run slowly.
Data Serialization and Persistence
When beginner coders first make a game in Unity, and they want to save their data, they typically use PlayerPrefs. For those who don’t know, PlayerPrefs is a class that allows you to store player preference between gaming sessions. It is typically not encoded in any way and sits on a well-known folder in your file storage. Hence, very easy to alter by any player with a little know-how.
Most times, we don’t want players changing their stats, progress, or possessions via the PlayerPrefs file. So, one way to prevent this is by Serializing your saved data. There are many ways to serialize your data, via JSON, or BinaryWriter. From there, your data can be encrypted and only accessible from your application.
It’s important to remember the distinction between PlayerPrefs and serialized/encrypted save data. We won’t go into detail on how to write your own save data files, but I encourage you to check out Serializable class documentation and BinaryWriter.
And if this all sounds out of your depth, there are plenty of low-cost save data Assets on the Unity Asset Store. For ease of use, I recommend Easy Save by Moodkie.
How to Make Games that just Feel GOOD to Play
How to make your games really juicy and fun!
Coroutines, Timers, and Threading
Coroutines are tricky for those who get into Unity and C# as their first programming foray. The concept of an “Asynchronous operation” is hard to describe on day one. The best comparison can be between cooking your own meal verssu ordering pizza.
When you cook your own meal, your mind and body is 100% dedicated to getting the food made (unless you are watching sitcom reruns in the background, but let’s set that aside). You can’t do anything else in the meantime. Coroutines are like ordering pizza, and cleaning your room while you wait for it to arrive. The food making operation is happening somewhere else, while you are free to do whatever needs to be doen. And gues what? Both methods return food!
Coroutines allow you to pause execution, return control to Unity, but then continue where it left off in the next frame. Coroutines are usually used for operations that happen multiple times over a period of time, or happen after some delay. Let’s say your player is poisoned — they will take 1 point of damage every second for 1 minute. With a coroutine, this is easy to write.
Don’t confuse coroutines and multithreading. Coroutines do not take advantage of threading, and do not provide any performance boosts. It simply allows you to continue execution, and come back to where it left off later. For timers, you can either use Coroutines or the Update Loop. For the poison example, its probably better to use Coroutines, because you do not need every frame to perform the health detraction.
“Thinking like a programmer” takes time and your road to becoming a proficient Unity developer is just starting. Hopefully you will keep in mind the major topics we discussed in this article, dig deeper into them, and find success making games!
Coding, design, and marketing are the three great pillars of an indie developer’s portfolio. Want to learn more about how to be a self-sufficient game maker? Check out some of my other articles and don't forget to leave a clap if you can jive with this article!