Software engineers are an optimistic bunch and, as such, we often underestimate the amount of work it takes to fully implement new features or make changes to an existing code base. A common mistake is to only consider how long it will take to write the code that's required to create that feature. In such cases, we forget to include the time it takes for several important tasks. We often need to spend time refactoring other subsystems to support the changes we're making. This can happen either because we didn't think it would be necessary at the time, or because we thought of a better way to implement it halfway through, which can quickly turn into a rabbit hole dive of redesign and refactoring if we don't plan far ahead. We should also consider the time that's needed for testing and documentation. Even if a QA team does a testing...
You're reading from Unity Game Optimization - Third Edition
Editor hotkey tips
The Editor is rife with hotkeys that can aid rapid development, and it's worth checking out the documentation. However, let's be honest—nobody reads the manual until they need something specific from it. In this section, we will go over some of the most useful, yet less well-known, hotkeys that are available when we're playing with the Unity Editor.
Working with GameObjects
GameObjects can be duplicated by selecting them in the Hierarchy window and pressing Ctrl + D (cmd + D). New, empty GameObjects can be created by...
Editor UI tips
The Editor's default behavior is designed to be efficient and satisfy every user; however, each of us is different, just like beautiful snowflakes, and so are our working preferences. Fortunately, Unity allows us to customize many aspects of the Editor's workflow. Let's see how with the following collection of tips.
Script Execution Order
We can prioritize which scripts will have their Update() and FixedUpdate() callbacks called before others by navigating to Edit | Project Settings | Script Execution Order. If we find ourselves trying to solve complex problems using this feature (with the exception of time-sensitive systems, such as audio processing), it implies that we've got some very...
Scripting tips
If you are a developer, you will spend a lot of time editing code. While artists and designers are playing with colorful images and visual effects, you may find yourself stuck in the black and white code editor domain. Coding may be hard sometimes, but it doesn't need to be tedious. In the following tips, we will learn how to simplify some of the most boring parts of the job.
General
We can modify various templates of the new script, as well as shader and compute shader files. This can be helpful if we want to remove the empty Update stubs which, as we covered in Chapter 2, Scripting Strategies, can cause unnecessary runtime overhead. These files can be found in the following locations:
- Windows: <Unity...
External tips
The following tips and tricks are related to topics outside the Unity Editor itself but can help Unity development workflow enormously.
The Twitter hashtag #unitytips is a great resource for useful tips and tricks for Unity development and is, in fact, where many of the tips in this chapter originate from. However, hashtags are difficult to filter for tips you haven't seen before, and it tends to be abused for marketing. A great resource that pulls together a bundle of weekly tips from #unitytips can be found at http://devdog.io/blog.
Googling Unity-related problems or concerns can be made a lot faster if we start the search with site:unity3d.com, which will filter all the results so that only those under the unity3d.com domain will appear.
If the Unity Editor crashes, for whatever reason, then we can potentially restore our scene by renaming the following file...
Other tips
Finally, this section contains tips that didn't quite fit into the other categories.
It's always a good idea to organize our scenes using empty GameObjects and use them as parents for a group of objects while naming them something sensible for that group. The only drawback to this method is that the empty object's transform is included during position or rotation changes and is included during recalculations. As we know, reparenting GameObject to another transform has its own costs. Proper object referencing, transform change caching, and/or use of localPosition/localRotation can be used to solve some of these problems adequately. In almost all cases, the benefits of having a workflow from scene organization are significantly more valuable than such trivial performance losses.
Animator Override Controllers were introduced way back in Unity v4.3 but tend...
Summary
This brings us to the end of this book. Hopefully, you have enjoyed the ride. To reiterate, perhaps the most important tip in this book is to always make sure that you verify the source of the performance bottleneck via benchmarking before making a single change. The last thing we want to waste time on is chasing ghosts in the code base when 5 minutes of Profiler testing can save us an entire day of work. In a lot of cases, the solution requires a cost-benefit analysis to determine whether we're not sacrificing too much in any other area at the risk of adding further bottlenecks. Make sure that you have a reasonable understanding of the root cause of the bottleneck to avoid putting other performance metrics at risk. To also reiterate the second most important tip in this book, always profile and test after making changes to ensure they had the intended effect.
Performance...