Copyright (c) 2020 Me First LLC
Enabling IL2CPP on your Unity builds will significantly boost your performance and help you transform your game into something truly great.
📌 When building a project using IL2CPP, Unity converts IL code from scripts and assemblies to C++, before creating a native binary file (.exe, apk, .xap, for example) for your chosen platform. Some of the uses for IL2CPP include increasing the performance, security, and platform compatibility of your Unity projects.
📌 This is different from the old Mono implementation that uses JIT (just in time) compilation.
📌 Compiling C++ to a native binary is a huge performance advantage from Mono JIT.
📌 There is no warm-up the first time you call a method with IL2CPP. Everything is compiled when the native binary is created.
📌 IL2CPP will cause your binary to be larger, but you can enable code stripping to help mitigate this issue.
📌 Build times with IL2CPP are longer than Mono, however in most cases, it is well worth it when creating a build people will play.
📌 Unity Editor still runs Mono. This is a good thing because it takes less time to recompile your scripts and in most cases, your computer is more powerful than the devices it will run on.
📌 IL2CPP is now a requirement for iOS and is the default for Android builds.
📌 IL2CPP relies on C++ compilers not implemented by Unity. This is a very good thing. Modern C++ compilers very stable and are great at compiler time optimizations.
📌 Reflection in C# causes IL2CPP to generate "metadata" embedded in C++ so that "reflection" can occur in the C++ code. This increases code size and may even lead to the embarrassing "too much code" issue Unity suffers from on mobile platforms.
Here are some super basic tips to increase your game's performance in Unity
📌 Only run code when things change. Instead of constantly polling and checking a state inside Update, try using Events and Actions to trigger code when something changes.
📌 If polling is required, then try only running your code every N frames or after a delay. Your AI code probably does not need to fire every frame.
📌 Move code out of loops when they can be run once, before, or after.
📌 Cache references and values instead of calculating them every time. GetComponent is included.
📌 Pool objects instead of Instantiating everything. Keep GameObjects in a list and when they are no longer needed, disable them. Enable them later as needed.
📌 Never use SendMessage and Camera.main. They are slow.
📌 Do not use FindObjectOfType. Instead, serialize a reference and link it in the Editor. Alternatively, you can create a singleton and use the reference directly.
📌 Avoid Vector3.Distance and Vector2.Magnitude because they use square root calculations. When possible, use Vector3.sqrMagnitude.
📌 Manually call System.GC.Collect() during loading screens or scene transitions.
📌 If you're getting large CPU spikes from garbage collection, then try incremental garbage collection.
📌 Disable/Enable MeshRenderer's using MeshRenderers.enabled. There is overhead activating and deactivating GameObject's with SetActive.
📌 Avoid calling DestroyImmediate.
📌 Store settings inside of ScriptableObjects instead of Prefabs. This avoids redundant variables allocated for prefabs using the same settings.
Can you handle the Truth? Let's break misconceptions and look at some common Game Developer myths.
📌 Making games is like playing games. Eating is not like cooking, the same goes for making games. Game development boils down to problem solving, creativity, blood, sweat, and tears. Understand what you're getting into when you start your game dev career.
📌 Casual games don't matter. The world consists of individuals who are fundamentally different. Some people like hardcore RPGs and some like casual games. Developing a good casual game is extremely difficult and there's a lot of money to be made in the casual space.
📌 People will steal your ideas. Many developers tend to keep their ideas secret for fear of idea-theft. Video game clones do exist, but only after a game becomes very profitable. Theft occurs from time to time but it's commonly blown out of proportion; be smart but let go of the paranoia.
📌 Designing games is easy. Knowing skills like programming, 3d modeling, and photoshop does not make you a good game designer. Great game design comes from practice and experience. Studying and evaluating design in games will help, but the heart of the design is forged in creation, feedback, and having honest evaluations of your own work.
📌 This is implemented with a prefab.
📌 The screen is controlled through a TextSelectorUi script at the root of the prefab.
📌 The controller code must manually call Show() on the TextSelectorUi.
📌 Using a custom script provides a great advantage over hardcoding text in code or in the prefab itself. It allows text changes, prefab reuse, and dynamic population of the title and text fields.
📌 The TextSelectorUi provides an interface that may be expanded upon in the future. This gives us flexibility, which is very important in fast-moving game development.
📌 If the script did not use Show(), but instead started inside OnEnable and ended in OnDisable, then the flexibility and future-proofing of this screen would be severely limited.
📌 The screen appears using a DOTween Fade. This is invoked in code, performant, and easy to implement. However, it is not as flexible as using an Animator for elaborate animations.
📌 If required, this could easily be refactored to use an Animator instead of DOTween. This would be a simple refactor, only requiring changes inside this single prefab.
Unity 2019 LTS is now the latest Unity version with "Long Term Support."
🎮 The focus of the LTS version is stability and will continually receive bug fixes for the next two years.
🎮 Using LTS can help bring long term stability to your game and your development process.
🎮 2019 LTS has the benefit of supporting the Scriptable Render Pipeline, Shader Graph, Nested Prefabs, and much more. Features that 2018 LTS does not support.
➡️ It's common for minor version updates to introduce new bugs with new features.
➡️ The specific version for 2019 is 2019.4.x LTS.
➡️ Early versions for 2019.1x, 2019.2x, and 2019.3x have issues and aren't recommended to launch new games on.
❗️ Constantly upgrading your Unity minor version is a huge headache and can lead to many issues.
❗️ LTS helps us avoid upgrade pains. Although LTS will continually release new hot-fix versions, these are restricted to bug fixes and are much more low risk than typical Unity upgrades.
❗️ Android developers should take notice of LTS since their game will run on many different devices. Android bug fixes can be found in almost every Unity update.
⭐️ Unity 2020 is just around the corner and promises many new toys and "game-changing" features.
⭐️ What is not talked about is Stability. New features and major changes always introduce runtime and Editor issues.
⭐️ After many years with Unity, I highly recommend waiting on the latest releases and jumping onto Unity 2019 LTS to benefit your games and your game development sanity.
The development cycle can require intense periods of grueling work. Here are some tips to keep your sanity and productivity.
📌Manage your time. Time is your most valuable asset. With only 24 hours in every day, reconsider if binging Tiger King is worth the cost.
📌Allocate "me time." Whether it's late at night or early in the morning, a period for you to unwind and destress will help you recover and prepare for work hours.
📌Define clear work hours. Set X amount of hours you'll work in one day and when it's over, close slack, and walk away. With a time limit, it also helps you stay productive at work; less time to goof off.
📌Have a social life. Plan events and activities on the weekend or in the afternoon. If you're a workaholic like me, It'll help you break away from the computer.
📌Become self-aware. When you're body feels unusually tired or you're starting to dislike your work, it's most likely a sign you're working too much.
📌Exercise and go outside. A 30-minute walk outside goes a long way to keep your lizard brain happy.
📌Keep your eye on the prize. Look at the work week ahead of you and make sense of how it fits in with your greater goal. Maybe you're building a website, game, or VR training app for hamsters. Understand every week, day, and hour helps you progress towards the finish line. 💬How do you keep your life - work relationship balanced.
The Unity Animator is an essential tool for making a beautiful game.
🕹 Animators use AnimationController assets. These assets allow you to create keyframe animations directly in the Unity Engine. For most animations, this is much better than trying to animate directly in code. Animations can be previewed as they are being modified, and don't require programming to update.
🕹 Animation Controllers are implemented with state machines. Each state represents an animation and transitions can be created between the states. A transition will blend between two different animations, so your character can transition smoothly from walking to running.
🕹 Animation Controllers are automatically created for models that also have animations. This is common for character models or any FBX that has animations attached. Custom scripts can then reference these animators, play animations, and trigger transitions between the different states.
🕹 The Unity animation system has a performance cost associated with it. In many cases the performance hit is negligible, but consider alternative solutions if you have thousands or hundreds of Animators active at the same time.
🕹 StateMachineBehaviour is a custom script that can be created and attached to a specific state in an AnimationController. Methods for Enter, Update, and Exit may be implemented for each state. This is good for creating or toggling special effects when an animation state is entered. 💬 What do you think about the Unity Animation System?
📌 I've been using Git for over 10 years and it is my recommended version control system for the vast majority of projects. It empowers parallel development through branching and local repositories and is a great solution for projects with many mergeable files.
📌 For beginners, Git basically allows you to track and share versions of your project with the ability to rollback and check out any previous version you committed. An example: I implement a jump attack in the morning and commit my changes in Git. Another developer, Jeb pulls my changes but accidentally deletes some of my code. I can use Git to recover my changes without deleting Jeb's other changes.
📌 Git command line. After all these years, I have yet to find a Git GUI which can compete with the speed, power, and flexibility of the command line. Imagine pushing a branch to a remote origin while naming the branch a different name, this can all be done with one line. GUI's on the other hand, can be great for resolving merge conflicts.
📌 Binary conflicts are a common issue with Git. In game development, this is a common pain point since game projects have large binary assets. Git LFS supports large files and even has locking support, however locking is more complicated and harder to use than SVN or Perforce. It's common for a developer to use a Git GUI that does not support locking in the UI.
Yes, this is a thing. Hold onto your butts and welcome to Tabs vs Spaces. The contrived but important argument.
📌 The thing to stress here is consistency and you should adhere to the standard for whatever project you're working on.
📌 For new projects, you should define a clear standard of whether tabs or spaces will be used. Alignment issues can be caused when you mix the two, just ask Python.
📌 Tabs can easily be customized by programmers, setting them to two, four, or please don't, eight space width. If you're not careful with your coding style, changing this setting may break text alignment in your codebase. e.g. function parameters being aligned with tabs and spaces.
📌 A programmer with poor eyesight may use larger font sizes and a smaller tab width to save screen space. This kind of adjustment can't be done using spaces.
📌 Spaces set a visual standard that will be consistent among all editors and external tools. You don't have to worry about 8 space tabs in your diff tool or Github.
📌 Tabs saving disk-space is negligible in 2020.
📌 Smart tabs can be used in may IDE's, allowing you to hit tab and automatically insert x amount of spaces for you.
⭐️ I've used both in different projects for many years and didn't find any real productivity boost from either.
⭐️ I've grown to really dislike alignment coding styles that you can use with spaces. I prefer indentation.
⭐️Many legacy projects and third party libraries have text alignment and use spaces. Dive into external code and it may appear incorrectly if you a different tab-width.
⭐️ Headaches come from people using different tab space width. Even with a style guide, alignment issues and spaces will slip through the cracks with many devs working on the same project over time.
⭐️ After 15 years of programming, my preference is smart tabs, tab-width 2. However, I'm flexible on the matter. Use the best tool for the job.
Writing your first script is like entering an unknown world. Whether you have programming experience or not, here are some general tips that can help you.
📌 When writing a MonoBehavior, the name of your class must match the filename exactly. If your script file is not named "PlayerController", then Unity will be unable to find the script. This becomes apparent when you can't add the script.
📌 GetComponent results need to be cached. GetComponent is not a performant call and thus you do not want to be calling it multiple times every frame. The better strategy is to cache your component in Awake or Start and then use the cached reference in the rest of the code.
📌 Attribute SerializedField allows you to reveal private variables in the Unity Editor. There is no need to make all your variables public. C# coding styles and good programming standards still apply.
📌 Serializing variables should only be done for objects that need to be linked through the Unity Editor. Whether it's playing an animation on an Animator or applying a force to a Rigidbody, this is how you will reference and control GameObjects in code.
📌 When things don't work, the first place to look is the Console in the Unity Editor. Forgot to link your serialized _rigidBody variable in the Editor, then Unity will throw an exception when that variable is dereferenced.
📌 Understand the dangers of static variables. MonoBehaviors are created and destroyed with the GameObject they are associated with. Any static variables you set may persist even after that object is destroyed. Be sure to clean up static variables.
📌 Make a Prefab: Scripts, like Prefabs, may be reused and added to many GameObjects. Most likely you'll be building a hierarchy of GameObjects with your script on the root GameObject. Try making a prefab and dropping multiple in your scene.
Copyright (c) 2020 Me First LLC