Search Unity

Faster C# scripting with JetBrains Rider

August 13, 2019 in Games | 5 min. read
Topics covered

Is this article helpful for you?

Thank you for your feedback!

From time to time, we spotlight a tool from an Asset Store Partner that we believe some Unity developers might like to know more about. In this post, we feature JetBrains Rider, a C# script editor.

Rider provides a view of assets and packages, rich code editor with integrated source control, inspections and code completion.

Work faster with C#

As a developer, you know how frustrating it is to keep switching between Unity and your script editor. You’d rather focus on your game instead of being bogged down in your code. JetBrains developed Rider, an integrated development environment (IDE), to help C# programmers navigate Unity, so you don’t waste time looking for files or performing detail work that could be automated. See if some of the features described below might make your workflow more efficient and productive.

Find what you need fast

The Shift+Shift keyboard shortcut activates the tool’s Search Everywhere feature, which helps you navigate your project as efficiently as possible. You can hit Shift+Shift and start typing to find your classes, files or symbols. Rider uses a “smart” algorithm, so you can even use the initial letters of the words that make up a class or method name.

The Search Everywhere dialog quickly allows searching for project classes, files, symbols and even menu items and preferences in the editor itself

Get your code down quicker

Rider can also help you write code faster by suggesting and completing all of the event functions in Unity classes. The application has full knowledge of the Unity API, from Unity 5.0 to 2019.2.

Start typing a Unity event function and Rider will show all functions in a code completion list, and generate the method when selected

Pinpoint problems in your script

It doesn’t matter how fast you get the code written if it doesn’t work. Rider analyzes your code as you type, looking for common issues. From possible null reference exceptions to suggestions on new C# language features (anyone migrating to C# 7?), the IDE highlights any issues it finds in your code. Hit Alt+Enter and the software will safely rewrite your code to fix the issue. Rider has over 2,200 inspections, 450 quick fixes and more than 50 refactorings such as rename and extract class to contribute to improving the quality of your code.

Rider's inspections will suggest places where your code can be improved, and pressing Alt+Enter will show a menu of quick fixes to automatically rewrite the code

Discover Unity issues early

In addition to understanding C#, this IDE has deep knowledge of Unity. It highlights script components, serialized fields and even event handlers registered in scenes and Prefabs in the Editor. (And yes, renaming an event handler in C# will also update the usages in scenes and prefabs.)

More importantly, the tool can save you time by highlighting Unity-specific issues as you type. It can find issues that would normally be found only at runtime – after switching back to Unity, starting play mode and playing the game through to the right place – and fix them automatically.

For example, Rider can find:

  • typos in the string-literal arguments for Invoke or StartCoroutine

  • incorrect signatures for methods marked with Unity attributes

  • unintended bypass of the lifetime check of the underlying object (in C# 6) when null coalescing or conditional access operators don’t correspond to an explicit null check

  • why your script won’t serialize when you applied the SerializeField attribute, for example, if you applied it to a property (something easy to miss)

Rider understands how Unity uses your code and shows warnings in the editor before you encounter them at runtime.

Write faster C#

This IDE helps you write your code faster, but it also helps you write faster code.

It has turned many of Unity’s best practices for performance into inspections. For example, the software will help you:

Rider highlights Unity's performance best practices directly in the editor, with Alt+Enter quick fixes to automatically rewrite the code.

These inspections all have simple fixes, and you can use the Alt+Enter shortcut to quickly rewrite the code and fix them.

Rider can help with some less obvious issues too. It understands how Unity calls your code, and knows that your Update methods will be called frequently, essentially every frame. It knows they need to be optimized. The editor adds indicators to these methods, and to any time-consuming API calls made inside them, based on Unity’s best practices, such as calls to GetComponent or SendMessage. These indicators are meant to guide you, to inform you that these calls have a cost and you should be careful about using them, but it’s also important to know that using them isn’t wrong. 

For example, calling GetComponent inside Update is an expensive operation, and it is usually always best to move that call to Start or Awake, and the software can automate this. As another example, a call to SendMessage is also resource-intensive, and requires significant work to fix; Rider doesn’t show this as a warning, but uses the indicator to show that this method is a good target for profiling.

Update methods are marked as a performance critical context, enabling more inspections and highlights to avoid known expensive methods.

Rider has a built-in code profiler that can attach to the Unity Editor and provide profiling results to establish exactly what your code is doing, in the same editor you use to write your code.

Integrated code focussed profiling shows how much time is spent in each method.

JetBrains Rider is a smart C# editor for Unity scripting and offers many ways to improve your productivity, as well as the performance of your code. Watch this video to see how it works. You can check out JetBrains Rider on the Unity Asset Store, find out more details on JetBrains’ website, and keep up-to-date with the latest features on the JetBrains blog.

August 13, 2019 in Games | 5 min. read

Is this article helpful for you?

Thank you for your feedback!

Topics covered