Unity Development Hints & Tips
On occasion I’m asked what I would recommend to someone in
my position. Ironically enough it’s a question I’ve seen countless times before
and would throw my penny’s worth into the pot for fellow developers and game
designers.
Frame Timings Matter
Consider logging or monitoring the Time.deltaTime variable
as the first debug variable you want to observe. As stated in the documentation; Time.deltaTime
shows the period of time the previous frame took to process from start to end.
This variable will can highlight any obvious bottlenecks in your system as
early as possible, as well as seeing when processes "clump" up
together repeating over short bursts of poor performance. As you start to
add more objects the source of the delay is not always apparent but this variable
will at least highlight there is a problem.
Avoid OnGUI & Update Calls
Every frame Unity has to call every monobehaviour within the
scene, firing its Update routine. If you're running at the baseline of 60fps
that's every 0.017 seconds a call will be made to your class. Although this is
over simplifying the way Unity handles threading and other features every
action within these routines slows the frame time and creates a bottleneck.
Avoid it if possible using more event driven mechanics such as coroutines or
consider remaking the class to use less resource during update. Equally every
OnGUI call also fires every frame, but moreover drains frame-time using a
somewhat resource intensive system of displaying the GUI drawn in this routine.
Can you use a draw call from a GUITexture for the background? I would typically
tend to using up a draw call or two than using the OnGUI functions personally.
Use Coroutines
As mentioned in my "Coroutines
Coroutines Coroutines" Article the benefits of using coroutines are
massive and can reduce the use of Update can be avoided with them, and allows
much more control over a longer period of time. Developers from software
development backgrounds can often dismiss or miss them when transferring over
to Unity from other C# environments. Nesting Coroutines or Parallel Coroutines
used in conjunction with callback delegates can make AI and other complex
systems much simpler to build and more cost effective especially when using
this across different projects or within custom frameworks.
Waste Not Want Not
As your projects increase in quantity you'll see common
elements of code you want to use over and over. As John Warner highlighted
in his blog
If you're going to
invest the time to write code, you should be adding value to your business and
creative process as well!
Building a system will become only more valuable as you use
it more will add value to your business and make every game a progression in a
history of games development. Taking time on things like inventory or dialogue
systems that can become limited to configuration alone become massive time
savers.
Small iterative upgrades to systems can evolve as you expand
your libraries with each game leveraging the limited time you have as an indie
to work on games. Imagine an evening of setup could have 60% of your mechanics
ready to go, awaiting new assets... DAY 1! Which it can be the third or fourth
project, done right!
Customise the Editor
If you have used Unity for some time you will want to
consider starting to leverage the development IDE to build GUI for your
components and frameworks. A dialogue system, looping and deviating on
variables from gender to reputation with an NPC could be bothersome to set up
and populate for a large RPG, especially when taking multiple languages into
account. Building custom pop out panels, and visual items on screen aping the
animation window or even the sprite editor are possible within Unity given a
solid foundation in the code and can make these tasks much easier and
streamlined to complete.
Pool Objects at run time
Did you ever play the game Lemmings? Just think back for a
second; several Lemmings escape from the entrance hit the ground, and without
user interaction typically fall to their death shortly afterwards. When a
lemming "dies" the temptation may be to destroy the object or leave
it disabled where it is. At the same time your code will be spawning the new
lemmings at the entrance, incurring an overhead to create, initialise and
position the new lemming in place. Always consider ways to limit runtime
creation of objects where possible, assuming your game is not 100% generated at
runtime of course.
Testing Methodologies
Whatever level of development you intend some form of maintenance
and bug fixing is going to occur after customers start playing your game. The
difference between a smooth launch with positive reviews, and low end scores
detailing several bugs is ultimately up to the quality of your testing. Luckily
this probably is also applicable in the software development industry and
various evolving concepts for automating and managing testing exist already. Although limited a good starting point can be
found and given a quick google search of MVVM and Dependency Injection will get
you several current examples, probably in C#.
Watch Streams and / or YouTube
If you have a game there is probably going to be other games
that are similar in the market being reviewed. If you have an
"amazing" idea check if anyone tried the same thing before in a game.
This should not be used to steal ideas but to validate how small subsets of
people you’ve never met respond to a mechanic or system. See how that idea was
received by the streamer or reviewer. YouTube and Twitch provide invaluable
information that AAA companies had to pay for before these services existed.