Best IDE + AI integration for a smooth workflow in Unity?

Leaving the ‘how good is it really/skynet will kill us’ discussion aside, what is the best IDE + AI workflow integration you have tried? I’m going to try out Visual Studio Code + a chatGPT extension some folks put on github. But I also wanted to give copilot a shot.

I’m looking for 2 kinds of things mainly (though I’m sure there will be more that I just can’t imagine)

  1. The stuff ChatGPT does: just write in a comment ‘give me a script that does x’ and there it is. Just a starting point I know, but still useful/faster.

  2. Automate certain things. For example I’d like to define a rule that makes sure that whenever I subscribe to a method in OnEnable, I want to automatically unsubscribe in OnDisable. Or click on a variable and it will add a debug.log with a message. Or add a require component attribute when I use getcomponent in awake. Those kinds of little things that are just mindless work and cause bugs here and there because “oh, I forgot”

I’ll report back how my experiments go and would love to hear your experiences as well. I want to get to a point where I just wave my pages of crazy handwritten notes to the webcam and the scripts are done, so hopefully this is the first step :slight_smile:

Just be aware that Unity’s extension for Visual Studio Code hasn’t had updates for a couple of years, and it was recently announced that they will soon stop supporting it altogether.

3 Likes

It is deprecated, which was a huge blunder on unity’s side.

Additionally it is not working that well, for example, making project work properly in latest versions require editing launch json by hand, usually by copying it from another project.

Oh damn, that really sucks. The more I learn coding outside of Unity, the more I use it. According to the thread linked above, it’s by far the #1 IDE for developers.

I’m still using VS Code, and gonna continue to use it till it completely breaks. It is usable at the moment, though, like I said, making project WORK might require copying launch.json and altering it by hand. Otherwise you won’t have ability to debug. The debugger is a bit glitchy too, to be honest, and sometimes breaks. Buuut, you can still use it.

Regarding AI, I was looking into those projects before, basically, most of them are subscription SaaS and it is unclear whether they add any value. I also can’t really use any of the paid options without jumping through the hoops at the moment, so I couldn’t evaluate any of them. Github said something about copilot being available to opensource maintainers, so maybe that’s an angle worth pursuing in the future? I don’t know.

In my opinion, some of functionality you wish for may be still future tech at this point of t ime.

I tried out VS code with Unity and ran into the debugging issue. I got everything else to work fine without too much hassle, so even if I couldn’t get it to work, having VS on the side for debugging with breakpoints would be enough.

Anyhow, I’ve decided to try things out one step at a time and only use Visual Studio with github copilot for now, which so far seems to be quite useful. I think using AI tools efficiently takes some time and experimenting. I’m pretty much sold on it already though, like I write “//lazy instantiation” and it throws out the full code for a lazy instantiation, I can cycle through a few options with one button. One more word, “Awake” , and there’s the rest of the Singleton pattern. Exactly the kind of stuff I want to automate.

Once I’m more familiar with Copilot, I will try out ChatGPT. So far VS code is the only one (I compared VS, VS code and Rider) that has a more practical implementation with different requests to chatGPT built in. Rider has an extension that is basically just the browser inside the editor to ask questions faster. I’m sure we will see a lot more plug-ins in the near future.

I will report back here in a week or so.

For the debugger to work you need to edit launch.json. Previously the addon could generate it, but now it no longer can.

The launch.json file loks like this:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Unity Editor",
            "type": "unity",
            "path": "/c:/<your-path-to-unity-project>/Library/EditorInstance.json",
            "request": "launch"
        },
        {
            "name": "Windows Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "OSX Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "Linux Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "iOS Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "Android Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "Xbox One Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "PS4 Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "SwitchPlayer",
            "type": "unity",
            "request": "launch"
        }
    ]
}

Replace “” with path to the unity project, obviously, and c: is a drive letter you can alter.

Debugger should start to work, but it will still be sorta borked. Occasionally it will disconnect or timeout.

Thank you very much! I saw the error messages and thought I’d deal with that later :slight_smile: I’m sure it will come in handy when exploring chatGPT. So far there are none for VS, but several for VS Code and one with a very active community that looks like it will get the best out of it.

After trying out a bit I landed on Rider + Copilot. It feels unreal how much my productivity has increased and I’m growing much faster as a developer by doing more thinking and designing instead of typing out the things I already know. Don’t tell Github, but I’d easily pay 100$ or more a month for Copilot :wink:

Not having switched to Rider sooner might be the biggest mistake in my Unity journey. So many incredible useful and thoughtful tools that make working in Unity more fun and more productive.

I’m still using ChatGPT too, but copilot has the advantage that it is so nicely integrated that it keeps the flow.

I’m looking forward to all the tools that the near future will bring, it’s quite exciting.

Rider is absolutely amazing but I struggle the see utility in copilot since it only sees the current open script and without context it’s more annoying than helpful.

Learn how to give it good prompts by writing in depth summaries first, then it will auto generate very relevant methods. Same can be done with comments. If you use comments and summaries as prompts and really fill them out with detail, it usually generates exactly what you need first time :slight_smile: Coupled with riders suggestions, its a great way to write clean optimized code quickly :wink:

It has other people’s code, according to a recent lawsuit maybe a little bit too much :slight_smile:

As @MadeFromPolygons_1 suggested, writing comments helps a lot. I also found that sometimes you have to talk to it more like googling, like “//common stats for an RPG” will give you health, strength etc. fields.

https://www.youtube.com/watch?v=15k1HEBHYXc

And it takes some getting used to. Like connecting to an API will give you correct looking code, you confirm and find out that none of these methods exist…

I believe Visual Studio and Rider are used by most Unity programmers. Rider used to have many very useful Unity-specific features that Visual Studio lacked, but I think Visual Studio has caught up well on the feature set front, and I don’t really feel like I’m missing out on anything important anymore by using Visual Studio. A few brave souls here and there use Visual Studio Code, but you might find yourself struggling to match the full feature set of the full-blown IDEs by going this route, even with all the extensions available for it.

For the automation part, I think your best bet would be to write a custom linter extension for your IDE of choice. It could show warnings/errors in your IDE when it detects some of the patterns you mentioned, and even automatically fix them for you with the press of a button.

Another option would be to use software architecture to make it impossible to make some of the mistakes you mentioned. For example, instead of coders needing to remember to unsubscribe from events in OnDisable, you could have higher level systems handle subscribing and unsubscribing your components automatically when they just implement an interface.

1 Like

Maybe I overlooked some visual studio features, but Rider seems miles ahead in terms of a productive Unity workflow. I had my jaw drop in disbelieve a few times, it’s so damn good.

As for the unsubscribing to events, Copilot figured that out quickly. Now I just have to go into my Disable method and hit tab a few times and it will add unsubscribing exactly the way I’m subscribing in OnEnable.

If I don’t have one yet, I type “OnD” . Tab and done :slight_smile:

Your suggestion of an extension would be even better though, because it reduces the chance for simply overlooking stuff.

1 Like

There are still a few pretty useful looking features in Rider the Visual Studio lacks, but nothing that’d be a game changer for me.

My favorite feature would be getting warnings about using the null-conditional operator with UnityEngine.Objects, and that would be really nice to have - but that still wouldn’t warn about doing the same with interface type variables, so I’d still have to be basically just as careful about using it anyways.

Other coding hints like using CompareTag sound like they would be an awesome feature for a beginner, but I have a feeling they wouldn’t be that helpful in my case.

The Project view that mimics the one in Unity looks pretty nice, but I’m not sure how much I’d use it personally, because I almost always open script files using a keystroke launcher anyways and close the Project view to get more screen real estate for displaying the code.

The fact that it highlights serialized fields with a “Set by Unity” text seems pretty cool, but 99% of my serialized fields will already be marked by having the SerializeField attribute, so again I don’t see it as any sort of must-have feature.

If I could get Rider for free I would probably switch to it, but I’m also very happy with Visual Studio.

1 Like

I’ve used Rider for about two years now and every time I accidentally set up a new Unity install and use Visual Studio instead I miss basically every QoL improvement and feature that Rider brings to the table. The things listed here are just the Unity specific features, not the general features of the IDE itself. Refactoring is dramatically improved over VS; code analysis in Rider is a dream, which can be critically important on larger projects, especially when other developers are involved; and its debugging tools are basically second to none.

Rider outclasses Visual Studio in basically every way both with its Unity specific features and its general IDE features.

3 Likes

Things like extract method in Visual Studio could definitely be improved upon… if you extract something from within a for/foreach loop, it’s not smart enough to replace continue with return for example. That’s could be one area where Rider clearly outshines.

I do remember that code analysis was pretty great in ReSharper back when I used it (years ago)! Nowadays I’m using SonarLint. I have no idea how it compares to Rider, but it has has 4800+ rules (Rider’s has 2500+ built-in) and can help catch some issues in the code.

Being able to add break points to automatically decompiled DLL code does sound like an interesting feature!

Maybe I should give Rider another go at some point. I’ve only played around with it for a handful of days, probably not long enough to get a good feel for how much better it’s refactoring tools are etc.

I can only recommend every Unity developer to take advantage of the 30 day free trial and watch the recent webinar on rider + Unity and read some of the docs. The difference is night and day.

I was already amazed but now I stumbled upon breakpoints. You can set conditions for them based on other values, you can turn them into simple asserts, custom messages, turn them into Unity pause points and with the breakpoint window you can see and tweak them all in one place.

2 Likes

Agreed that Rider is easily the best choice for doing serious Unity work both on Mac and Windows, hands down. This has become the consensus across all of our studios (a high number of engineers who don’t easily agree on such things).

As for the AI assistants topic in this thread, it sounds like they only help you barf up frequently repeated boiler plate code. If you have a lot of that, then you should fix that instead of letting an AI make you comfortable with it, right?

I tried copilot for only a few hours a while back and it didn’t seem to add any value, but it wasn’t a fair test. I hope to try again sometime soon to see if there’s more value than there seems to be.

1 Like

It does encourage boilerplate code because it’s so easy to accept the suggestion and it doesn’t consider the whole project yet. So in the example I gave above where you make a new class and type “// lazy instantiation” and it spits out a working lazy instantiated singleton, you can do that for every class and it wouldn’t come up with the idea to use a base class instead (or not a singleton at all :wink: ). With the current rate of progress in AI, I assume this is only a matter of time.

Once you get used to using it and don’t turn off your brain, I think it helps tremendously. I spend a lot more time thinking about the actual logic and systems than typing out boring syntax, so I think there is a compounding effect that makes me grow faster as a developer.

Just like Rider I can only encourage developers to give it a shot with the free trial, and understand that it is a quirky tool that takes a bit of time (it literally needs time to learn from you as well). It took me a while to get a feel for it, but now I often know where it’s going to fail me completely and where it will very reliably turn a comment into exactly what I wanted.