Using JetBrains Rider with Unity
Part 2 — After a little over a Week
My previous article on going from Visual Studio to Rider was meant as a direct first impression: I wrote everything down literally while playing with JetBrains Rider for the first few hours and put recorded everything that I noticed into the article, immediately when I noticed it.
This time, I spent a significantly more time just working with Rider 2019.2 (which moved from Early Access to released in this week) and collected what I felt might be useful for people who, like me, make the move from Visual Studio to Rider. I use Rider as IDE for Virtual Reality game development with Unity. If you’re a Web developer, this article may not be that useful for you.
TL;DR
Visual Studio is awesome, JetBrains Rider is awesome. If you like ReSharper, it’s likely that you will enjoy switching from Visual Studio to Rider without any second thoughts at all. Personally, I never was a fan of ReSharper and some of the things I found annoying about ReSharper did also annoy me a little about Rider … but overall, I’m very glad that I have moved over.
A Word on Pricing
Obviously, Visual Studio Community Edition is free, which is a price that is impossible to beat. Rider does have free options for students and teachers, open source projects, user groups and a few others, and also reduced prices for startups, educational organizations and so forth. Check out Special Offers to see if any of those apply to you.
That said, also have a look at their subscription model. I’m not a fan of subscriptions for software licensing at all — but what they offer is really fair (after a one year subscription, you get a perpetual fallback license). Microsoft has obvious reasons for offering Visual Studio Community Edition for free, and if for some reason, you cannot use Community Edition, Visual Studio Professional or Enterprise costs quite a bit more than Rider.
I have dedicated some space on Why the Company Behind a Product Matters … a lot! in my previous article. In a nutshell, I care a lot about what kind of company or corporation I want to support by paying for their products, and of course, also what I can afford. JetBrains is a comparatively small company without external funding that needs its customers’ support. Microsoft is a huge corporation that can easily afford to offer Visual Studio Community Edition to everyone for free just to stay dominant in the market.
So how did the two compare for me?
Responsiveness / Performance
Responsiveness when clicking files or log statements in Unity to open Rider is blazingly fast. This is where performance matters most to me.
Starting up Rider seems kind of slow, and even the splash screen takes a while to show up, sometimes making you wonder if it even is starting. That isn’t great but it hardly bothered me while actually doing work because I never need to close Rider once it’s started up.
When working with Visual Studio and Unity, I experience frequent hiccups, sometimes very annoying ones, where Unity just “stops working” until I realize that Visual Studio is waiting for me to confirm reloading the solution somewhere in the background.*
Nothing like this ever happened to me while using Rider.
*[UPDATE (2019–08–17): Performance may be better when using the most recent Visual Studio / Visual Studio Tools for Unity versions — thanks to Sebastien Lebreton for pointing me to the Visual Studio Tools for Unity Changelog]
Plenty of (false positive) Error Messages — fixed!
In the previous article, I had still used the Early Access version of Rider 2019.2. I sent JetBrains two repro-projects with files that incorrectly showed up as having errors — and both of these issues are now fixed in the released version.
Unity Bug: Clicking Log Messages pointing to Files in Packages
Given how much better the project explorer looks in Rider compared to Visual Studio, for Unity projects (see screenshot below), I was hoping that one of the more annoying issues in Unity would be fixed by switching to Rider as well.
Unfortunately, just like with Visual Studio, clicking log messages or the new Unity 2019.1 stack trace lines of files that are located in packages does not work. I filed a bug with Unity, this does not seem to be an issue with Rider.
*[UPDATE (2019–08–17): The Unity Project Explorer does show Packages since 4.1.0.0 / May 21, 2019 — thanks to Sebastien Lebreton for pointing me to the Visual Studio Tools for Unity Changelog]
Auto-Saving Code Changes
Most of the time, auto-saving code changes, like Rider does it, is really nice. If I want to, I can always revert via version control. BUT: Sometimes, when updating Unity, the fastest way to get rid of all the warnings is double-clicking the warning in Unity, fixing the issue in Visual Studio not saving those changes, going back to Unity, clicking the next warning, and so forth. There are a few other situations where making changes in many files before saving them all at once is useful. For me, Ctrl+Shift+S has become automatic, so I only have to think about not doing it before going back to Unity in those cases where auto-save slows my workflow down.
So it would be nice to be able to switch auto-save off, and I haven’t found a way to do that.
Auto-Adding Using Statements
When you use a class that resides in a namespace that you haven’t imported, Rider automatically adds a using-statement on top of the file when you let it auto-complete the class name. Visual Studio can do this for you — but it’s a separate step that you have to trigger. And I like it better that way. In general, I don’t want an IDE to do anything in another part of my file automatically that I can’t easily see unless I tell it so.
This one is surprisingly annoying because we often have little editor helpers in classes that otherwise are runtime-only classes, so the best way to handle these cases is to simply wrap the editor-code in #if UNITY_EDITOR and make sure to fully quality the classes we use from the UnityEditor namespace.
And I haven’t found a way to switch this off.
Refactoring Inspector Variable Names
This is a very nice one: Rider knows that changing a public member variable of a MonoBehaviour will break serialization and offers to automatically add the FormerlySerializedAs attribute. This is a really nice feature that does save some time during refactoring. It also shows how deeply Unity and Rider are integrated. More on that below.
I only had to make it behave properly because with the default settings, Rider puts attributes in the same line as declarations. But that’s easy enough to fix:
Formatting: Putting Attributes in same line as Declarations
Rider by default turns this:
[Header("Different Floors")]
public Toggle gpuOptimized;
Into this:
[Header("Different Floors")] public Toggle gpuOptimized;
So I had to figure out where this is set up … … … well, it’s here:
This message is a little misleading:
Actually, this is the EditorConfig of the whole solution, so it overrides everything in \Assets\. But either way, that’s what I actually want to change, so I click Edit:
… and don’t forget to click “Save”, like I did the first time when I had changed this. Also, with the solution settings “Save” button, make sure to not just click “Save” but pick “Solution ‘your solution’ team-shared”:
Opening separate Windows to do Things
This is probably the thing I find most annoying about Rider compared to Visual Studio in terms of user experience: In Visual Studio, I can set up pretty much everything that I care about as panes inside the main layout. In some cases, like the project explorer search, the search text field is integrated into the Project Explorer. This is awesome, I love it!
In Rider, on the other hand, there are a lot of things that I use a lot that open separate Windows. Like, most of the searches.
Or, one of the things I missed from Visual Studio: Navigating previous locations. In Visual Studio, I have a “back button” right in the toolbar. ̶I̶ ̶h̶a̶v̶e̶n̶’̶t̶ ̶f̶o̶u̶n̶d̶ ̶a̶n̶y̶t̶h̶i̶n̶g̶ ̶l̶i̶k̶e̶ ̶t̶h̶a̶t̶ ̶i̶n̶ ̶R̶i̶d̶e̶r̶.̶ What I did find was a Window with previous locations (View / Recent Locations, or Ctrl+Shift+E). It’s good to have that and I can do Ctrl+Shift+E, then cursor down, then enter:
But I’d rather just click that little button once … and turns out I can:
Simply switch on the Toolbar:
And this:
Will turn into this:
As you can see, that “Toolbar” really only changes the layout and adds five buttons, of which I only really need the last two (navigate back/forth in code location history).
Quickly Opening a File by Name
As I mentioned in the previous article, I do love Visual Studio. One of the few of my favorite features that I wasn’t able to find in Rider:
That’s something I do miss a little in Rider because I need to remember Ctrl+Shift+T here … but I guess I will remember it. Also, in case I do forget, I can simply close all files to get a little reminder:
So, by pressing Ctrl+Shift+T, I get this little gem:
Navigating the Structure of a Code File
Visual Studio has three dropdowns in the code editor, for namespace, class, and all the class members. I don’t think a lot of people have multiple namespaces in a single code file, so that one seems a bit strange there. Multiple classes, structs or enums in a single code file are kind of common, though. And a way to navigate members is definitely useful.
Rider handles this differently, and in my humble opinion, in a better way:
You see both, the namespace, folders and actual file name in a little breadcrumb on top:
There’s no dropdown for the members — those (as well as different classes, structs or enums, if you have them in the same file), are in a separate pane:
I like this better because seeing that list all the time makes it much easier to navigate for me. Also, one little detail is that you can sort by alphabet, which often will make navigating much faster, and you can autoscroll in both directions, so navigating in code will highlight the member the cursor currently is in. This is very cool.
Disabling Code Analysis for the Whole Solution? Don’t!
Have you noticed the massive amount of warnings and hints and whatnot in the previous screenshot (all the little yellow lines in the scrollbar area)? Rider, just like ReSharper, really wants to tell you how to code. And quite often, this is very useful. I have already learned a few things that I wasn’t aware of and that definitely help improve my code quality. That’s awesome!
But there are also a lot of things that either are actually bad advice (there is a reason I use for instead of foreach many times in Unity: the former does not allocate memory, the latter does), or maybe not as important as Rider would think (boxing allocations are often auto-optimized out when you compile to IL2CPP). Another issue is that we use a lot of 3rd party packages, like the SteamVR Unity Plugin, that has its own style, and there’s really no point in starting to change it.
How can I just disable all the annoying stuff?
Probably the best way is to do this carefully, one step at a time, and that is actually quite easy:
One really nice thing to point out is “Disable once with comment”, which will add a comment which says that this was disabled. There are often also options to disable this for the full file, or method.
I could, of course, also go through all the settings at once, here:
… and then continue developing my game in a week or two.
Nope.
At first, I thought I could simply disable this once and for all, by simply disabling code analysis:
Unfortunately, this will also remove all kinds of useful things like advanced code highlighting. So you usually won’t want to disable this globally.
Fortunately, as you may remember from my previous article on going from Visual Studio to JetBrains Rider as Unity developer, that this can also easily be done for individual files, while editing them:
This is useful. But even just taking it down to “Syntax” unfortunately also kills highlighting classes and other useful things. So that’s one of the areas where I hope Rider will still evolve, and according to one of its developers, this is in fact an area that they are working on quite a bit, so I’m confident that this will become just as awesome as the rest of what I have seen from Rider so far.
Font Sizes in Visual Studio vs. Rider on a 4K Monitor
This is most likely related to a Windows feature in the Display Settings called “Scale and layout”:
If you don’t have a high resolution display, this will be at 100%, and you have probably wondered why many of my screenshots look so … um … big. If you have a 27" 4K monitor, 150% is a really comfortable setting. So everything is scaled up a little. Unity doesn’t handle this too well, yet … even though it might in 2019.2 or 2019.3. Actually, it got much better in 2018, IIRC. But let me not digress. Even with that setting, I like my font comparatively large in Visual Studio. I use Consolas, at 16 pt.
Not sure if maybe Rider uses px as font size unit, instead of pt. But either way, to get the same results, in need to crank this up to 20 here. And also, no line spacing. Now, watch this screen carefully:
The search keyword highlighting is really awesome. But more important is that Editor / Font gets overridden by the Color scheme font, and Rider lets you know about this with a little warning that you can click, which takes you to where the font is overridden:
Ok, maybe I should really uncheck this. Done. Clicking myself back to the other one via “default”.
Noteworthy is that to get almost the same results, I had to use line spacing 0.9, which seems a little unusual to me. But really, that was just a heads up.
Here’s the result — almost the same font-size and line spacing, except in Visual Studio, it’s Consolas 16pt and I didn’t see a way to change the line spacing, and in Rider it’s 20 (something) and line spacing is set to 0.9:
Improved Unity Integration in Rider
Another nice little thing you can see in the screenshot above is that Rider has Unity’s Play Button right in its toolbar, and also Attach to Unity Editor. That’s a nice little touch — but let me conclude this article with what got me started looking into Rider, and what I have now come to appreciate a lot as a feature that shows how tightly the integration between an IDE and Unity can be:
This quickly give me a list of the scenes in our project that override this value in the inspector. It’s a bit of a random example because we overwrite these values during our build-process. Rider doesn’t know that but I do.
But Rider can also tell me things that I may not remember and be fully aware of. Let’s take this example that also shows that this works with prefabs as well:
This quickly gives me a list of all the Flying Note prefabs that are not pooled, yet (between you and me: those will never be pooled because this is from a legacy system that we’ll drop out of the game once our beatmap editor is completed, and we have replaced the old gameplay with new gameplay built with that new editor).
One more — how did we override the score property? Rider knows:
What’s even better: I can click on any of those, and it will immediately ping the prefab in the editor.
They also have a more complete list of the Unity-specific features that were added in JetBrains Rider 2019.2. Make sure to also check out their Unity ReSharper/Rider Repository on GitHub (changelog).
Just playing with this, and writing about it, gives me some pretty cool ideas for feature requests that can be built on top of the JetBrains devs have already built into JetBrains Rider.
Conclusion
Rider came kind of out of nowhere for me. Had anyone told me that I’d replace Visual Studio for another IDE two weeks ago, I would have laughed at them. And here I am, now using Rider instead of Visual Studio for our main project, and I’m very happy about this.
If you’re interested in VR, make sure to check out Holodance and wishlist Beat the Rhythm. If you feel generous and would like to support an independent game developer, I also have a Patreon that you can support.
And if you like Visual Studio but feel you like Rider even more: Download the JetBrains Rider Trial!