Rider 2023.1: Discovering New Features for Unity Developers

Written by denyskondratev | Published 2023/04/26
Tech Story Tags: unity | game-development | ui-toolkit | rider | jetbrians-rider | gamedev | hackernoon-top-story | coding

TLDRThe Rider 2023.1 release introduces new features for Unity developers, including Android game debugging via USB, UI Toolkit templates for creating custom Unity Editor extensions, and support for Unity's Data-Oriented Technology Stack (DOTS). These updates simplify the debugging process, improve UI creation, and enhance Rider's support for Unity development, making it a top choice as an IDE for Unity developers.via the TL;DR App

Uncover Rider 2023.1, which solidifies Rider’s position as the best IDE for Unity development. We’ll explore its many (and in some cases, very-long awaited features) and find out how they simplify development and empower devs to create better, more efficient games.

Hello everyone, my name is Denis Kondratev, and I’m a Unity Developer at MY.GAMES. In my view, Rider, the IDE from JetBrains, has long been established as the best IDE for Unity development. Further, with the recent release of Rider 2023.1, many new features were added to make developer lives easier. Once again, JetBrains continues to set a high bar, and they have not disappointed.

An overview of the update

This new version allows us to debug games running on Android devices via USB cable. In general, it simplifies debugging by automatically creating temporary run configurations for connected players, optimizing subsequent sessions, and allowing easy saving and sharing with your team on various platforms. And still, for some developers, another important feature is support for localized documentation right within the IDE itself.

It's also time to finally dive deeper into and explore the UI Toolkit.

Rider has added three templates for UI extensions for the Unity Editor based on the UI Toolkit.

Rider 2023.1 includes improvements in identifying fields with the [SerializeReference] attribute, finding C# usage in Unity animations (which was sorely missed), and formatting [Header] attributes.

In general, many enhancements have been added for working with C#. And last but not least, the sweetest part of all: the long-awaited DOTS support from JetBrains.

With that out of the way, let’s briefly review and see whether or not it's worth upgrading to the latest version of Rider. If you haven't been using this IDE yet, this article will be useful for you as well.

Debugging Android games via USB

Sometimes, even though a game behaves perfectly fine in the Unity editor, things don't go so smoothly on real devices. Rider now allows us to debug code directly on a device via USB – and that's inspiring.

For this feature to work, it’s important to remember that the build must be compiled with the Development Build and Script Debugging options enabled.

I'd also like to remind you that the device itself should also be set up properly, and first of all, Developer Mode must be enabled on the device:

  1. Go to the "Settings" menu.
  2. Then, "About device" or "About phone".
  3. Next, "Software information".
  4. Find the "Build number" item there and tap on it several times – at least seven times.
  5. This will make the device available for debugging and open the "Developer options" menu.

Also, another simple way to find the "Build number" item is to search for it in the settings.

Next, enable "USB debugging" in the "Developer options" menu which will appear.

A couple more steps: launch your game on the device, and in Rider's main menu, click "Run" and then "Attach to Unity Process...". In the opened window, select the Android device with your application.

Everything is ready! You can set breakpoints and debug your game directly from the device! Don't hesitate to utilize this powerful debugging tool and enhance your game development process.

Another note: As soon as you start debugging for the first time, Rider will automatically create a temporary run configuration for the Android player. If you want to save the run configuration for future use, you can do so and share it with your team.

New Templates for UI Toolkit

Of course, we’re all very familiar with the old, good, (and at the same time terribly inflexible) IMGUI. However, for a long time, the Unity team has been working on a new UI Toolkit package to improve our experience creating game UIs. Starting with Unity 2022.2, it’s recommended to use a new approach when creating a UI in the editor.

The UI Toolkit is a separate, deep topic. I will only say that the new approach offers a more convenient and, to some extent, more common approach to creating UIs. If you have experience with HTML and CSS, it will be very easy for you to adapt; but even without that, I would also advise others not to delay in mastering UI Toolkit.

Rider, for Unity 2022.2 projects or older, now offers the use of new templates by default. Let's try one of them. For this, first, we’ll create a simple ScriptableObject to describe the items in the game:

[CreateAssetMenu(fileName = "GameItem", menuName = "Game Item", order = 0)]
public class GameItem : ScriptableObject
{
    public string itemName;
    public int weight;
    public int price;
}

Let's create a custom editor for this ScriptableObject. To do this, right-click on the Editor folder in Rider, then Add, and select Unity Script.

In the opened window, select Custom Editor. Let's name our editor GameItemEditor.

In the CustomEditor attribute, indicate that the created editor is intended for the GameItem class.

using UnityEditor;
using UnityEngine.UIElements;

[CustomEditor(typeof(GameItem))]
public class GameItemEditor : Editor
{
   public override VisualElement CreateInspectorGUI()
   {
       return base.CreateInspectorGUI();
   }
}

Now, open Window -> UI Toolkit -> UI Builder. In the Viewport, save the current UI Document and name it GameItem.uxml. From the Library window, add three fields that will correspond to our GameItem class fields and give them appropriate names.

Working with UI Toolkit has several obvious advantages: the ability to graphically edit UXML documents is available right out of the box through UI Builder, as well as editing via programming – somewhat similar to IGMUI. Now, the UI display style can be set in USS (which is similar in essence to CSS) and then reused in the project. Oh, how this was missing! And automatic undo support is also present.

Another notable feature is automatic data binding. Let's indicate the names of the GameItem class fields in the Binding Path fields.

Don't forget to save the document using the File -> Save As… menu in the Viewport window. (The hotkeys for saving, Ctrl-S / Cmd-S, won't help you here.)

You should get a UXML document composed of roughly the following content:

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
   <ui:TextField picking-mode="Ignore" label="Name" name="Name" binding-path="itemName" />
   <ui:IntegerField label="Weight" value="0" name="Weight" binding-path="weight" readonly="false" />
   <ui:IntegerField label="Price" value="0" name="Price" binding-path="price" focusable="true" />
</ui:UXML>

Now, let's finish writing the GameItemEditor so that it forms the inspector directly from the UXML document:

[CustomEditor(typeof(GameItem))]
public class GameItemEditor : Editor
{
    public VisualTreeAsset treeAsset;
    
    public override VisualElement CreateInspectorGUI()
    {
        var inspector = new VisualElement();
        treeAsset.CloneTree(inspector);
        return inspector;
    }
}

Select the GameItemEditor script in the Project window and specify the created UI document GameItem.uxml for the Tree Asset field by simply dragging it there.

Our custom editor for the GameItem class is ready. You can experiment a little with the UI document and see how its changes will affect the display in the inspector.

The release of the new Rider 2023.1 is reason enough to delve into the study of UI Toolkit and understand all the benefits it offers!

Embracing the Power of DOTS

Unity's Data-Oriented Technology Stack, or simply DOTS, is a project that has been in development by the Unity team for many years. After almost a year without any updates, DOTS packages have moved from experimental status to pre-release, obtaining version 1.0.0. (At the time of writing this article, it’s 1.0.0-pre.65. And there is a promise of release in 2023.)

Despite the long development time and the doubts that some have had about DOTS, even giving up on waiting for the release, the new stack still amazes with its capabilities and performance.

Data-Oriented Design, or generally speaking, the Entity Component System (ECS), offers a completely different approach to game programming architecture. Unlike the familiar Object-Oriented Programming patterns, the focus here is on the separation of data and processing. In this kind of architecture, similar data is usually located close to each other in memory and allows systems to process it with incredible speed, especially if this can be done in a multi-threaded mode.

A huge amount of work has been done on DOTS, with native memory management mechanisms added so that they can be conveniently used directly from C#.

With the release of DOTS 1.0.0, many approaches to application development have changed, and in my opinion, they’ve become more convenient and intuitive.

Although there is still a lack of good documentation, there is enough to start diving into the incredibly productive world of DOTS and rewire your brain for ECS and multi-threaded data processing.

I previously released an article on gravity simulation using Gravity Simulation With Unity DOTS 1.0. If you want, you can also find many other educational materials for studying this stack. To test the new capabilities of Rider, I opened my old Wave Propagation project, which was written with the previous version of DOTS.

What always annoyed me was the many warnings issued by Rider or Visual Studio due to the specifics of writing code. Now the code looks clean and pleasant.

Finally! How I've been waiting for this! Rider officially supports DOTS, which undoubtedly makes it the number one IDE for Unity development. Now Rider truly understands what is right and what is not.

For example, in this piece of code:

public partial struct TransformingSystem : ISystem
{
   [BurstCompile]
   public void OnUpdate(ref SystemState state)
   {
       var field = SystemAPI.GetSingleton<Field>();
      
       var job = new TransformingJon
       {
           HeightScale = field.CellHeightScale,
           DeltaTime = SystemAPI.Time.fixedDeltaTime,
           FieldViscosity = field.Viscosity,
           MinHeight = field.MinHeight
       };

       job.ScheduleParallel();
   }
}

Rider suggested that now, for correct access to the singleton Field, OnCreate() needs to set the expectation through the method state.RequireForUpdate<Field>():

public partial struct TransformingSystem : ISystem
{
    public void OnCreate(ref SystemState state)
    {
        state.RequireForUpdate<Field>();
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        var field = SystemAPI.GetSingleton<Field>();
        
        var job = new TransformingJon
        {
            HeightScale = field.CellHeightScale,
            DeltaTime = SystemAPI.Time.fixedDeltaTime,
            FieldViscosity = field.Viscosity,
            MinHeight = field.MinHeight
        };

        job.ScheduleParallel();
    }
}

Also, templates for creating bakers for MonoBehaviors have appeared, and we’re offered to create a new component or add fields to an existing one.

Of course, not everything is perfect yet. When generating baker code, an outdated template is used. I got this code.

public class FieldAuthoring : MonoBehaviour
{
    public GameObject CellPrefab;
    public Field Field;
    public Impulse Impulse;

    public class FieldAuthoringBaker : Baker<FieldAuthoring>
    {
        public override void Bake(FieldAuthoring authoring)
        {
            AddComponent(new FieldComponentData
            {
                CellPrefab = GetEntity(authoring.CellPrefab),
                Field = authoring.Field,
                Impulse = authoring.Impulse
            });
        }
    }
}

public struct FieldComponentData : IComponentData
{
    public Entity CellPrefab;
    public Field Field;
    public Impulse Impulse;
}

Here, the already outdated methods GetEntity() and AddComponent() are used. Instead, component addition should now be done in this way:

public override void Bake(FieldAuthoring authoring)
{
    var entity = GetEntity(TransformUsageFlags.Dynamic);
    
    AddComponent(entity, new FieldComponentData
    {
        CellPrefab = GetEntity(authoring.CellPrefab, TransformUsageFlags.Dynamic),
        Field = authoring.Field,
        Impulse = authoring.Impulse
    });
}

Of course, you can change the templates yourself. But I think that the fix from JetBrains will not take long to arrive. The possibility of creating an authorizing MonoBehaviour with a baker for the component also exists. On the JetBrains blog, you can already find an article, which extensively describes the new capabilities when working with DOTS, so I see no point in describing the same here.

Conclusion

The release of Rider 2023.1 brings a wealth of new features and improvements for Unity developers, solidifying its position as the best IDE for Unity development. With enhanced debugging for Android devices, new templates for UI Toolkit, long-awaited DOTS support, and additional features like quick access to online documentation for Unity registry packages and localized API documentation, JetBrains continues to raise the bar for game development tools. These features not only simplify the development process but also empower developers to create better, more efficient games.

Further, Rider 2023.1 delivers several other updates, such as more accurate detection of serialized fields in code, improved support for finding C# in Unity animations, and the highly requested update to the formatting engine for placing [Header] attributes on a separate line. These enhancements contribute to a more streamlined and efficient development experience.

Whether you're an experienced Unity developer or just starting out, the release of Rider 2023.1 is worth exploring. The new features cater to a wide range of needs and help streamline the development process. If you haven't used Rider before, this release provides an excellent opportunity to experience its powerful features firsthand. For those who are already using Rider, upgrading to the latest version will undoubtedly enhance your game development workflow.

Embrace the latest advancements in Unity development with Rider 2023.1 and take your game projects to new heights. Don't miss the chance to improve your development experience and create more engaging, high-performance games.


Written by denyskondratev | Software Engineer | Unity Developer
Published by HackerNoon on 2023/04/26