Richard Fine’s top three for a better scripting experience

As a developer on Unity’s Sustained Engineering team, I’ve helped many customers improve their scripting. The tips on this page are my top three; follow these for more efficiency in your development, and less pain!

Key things you'll learn about:

1Learn to use the debugger effectively.

While you can go a long way diagnosing problems using Debug.Log, the debugger can help you diagnose a problem faster and in more depth. If you’ve never used it before, we have guides for both MonoDevelop and Visual Studio and if you have, I recommend taking the time to explore all the things the debugger will let you do, such as setting conditional breakpoints or using the Immediate window.

If you’re in MonoDevelop, to start using the Debugger, all you have to do is press the “Play” button in the top left of the window.

2Add the ScriptableObject class to your mental toolbox of scripting techniques.

The ScriptableObject class is an often-overlooked part of the Unity API. Understanding ScriptableObject can help you to build a much cleaner, more elegant architecture; it can help you to keep things simple, be more data-driven, and achieve a better separation of concerns in your project. I’d say more, but I already did in my talk at Unite LA–take a look for a full explanation of ScriptableObject, plus examples of how you might apply it. There’s also a video class from Unity’s Learn team.

3Optimize throughout your development process, not just at the end.

Sometimes the right answer to a performance problem is to change your game’s design, and the later in the project you optimize, the harder it will be to make that kind of change. When you’re optimizing, the Stats window in the Game view is a good start, but to really understand your problems you should use the Profiler–there’s a huge amount of information packed in there–and to get the most accurate results, you should profile your game while it is running as an actual build, rather than in the Editor.

The Profiler window.


 

More resources

Before I sign off, here are a couple more links you might want to check out:

  • If I was to give a fourth ‘top tip’ beyond the three above, it would be “learn to script the Editor effectively.” If you’ve not done any Editor scripting before, the talk “Editor scripting for noobs” from Unite Europe is a good introduction to the topic.
  • Unity’s Learn team have created a comprehensive set of scripting tutorials. The “Beginner Gameplay Scripting” ones are probably things you’re already familiar with, but keep scrolling and you’ll find more advanced topics, including C# features like generics, Unity architectural topics like effective AssetBundle usage, and an archive of the live training sessions they have run on topics like localization and object pooling.

Happy scripting!