Static Code Analysis options for Unity and/or Unreal

I’d be curious as to whether anyone has been having success with using code analysis tools with Unity or Unreal.

It seems like they would be useful tools in these arenas but seem complicated to integrate or deliver.

I’m talking about tools like Gendarme (for Mono, for Unity) or SonarQube/SonarLint.

Problems seem to include:

  • Inability for C# analysers to deal with Unity object structures (e.g. not having a reference to what a MonoBehaviour is or why they seem to have hanging Start() and Update() methods not apparently called by anything). Gendarme looks like it may have a hope here, but it (nor any attempts to integrate it with Unity) hasn’t been maintained for years now it seems.

  • C++ analyses like FxCop (aka VS Code Analysis) requires enterprise edition VS, or $7k per year language pack add-in for SonarQube, which otherwise offers free tools for C# and Java worlds. I understand why - complexity involved and the lack of easy access to aids like Reflection - but the difficulty of such things hasn’t stopped other impressive projects being delivered before and it seems like an opportunity begging.

Has anyone managed to have experience of a tool that works with the code from these engines? Or is the only way to eyeball the code yourself, with peer reviews, and remain extra vigilant with the code you write?

Some references I’ve been pulling together on the topic (particularly with respect to Unity because of C#) but haven’t wrapped my head around yet:

Static Analysis in Unity
Gendarme for Unity : a code analysis tool
Unity3d Gendarme Plugin
unity-gendarme
Unity Gendarmerie
Shades of Play: Code Analysis/Unity Performance Tips

I use Resharper for Visual Studio and it does have an extension specifically for Unity users with references to MonoBehaviour, besides a few other amazing functionalities. They offer a 30 days free trial period, I recommend it.

2 Likes

Hmm, ok, that’s an interesting direction.

I didn’t pay it much attention at first for these reasons:

  1. I do some of my development on Mac with Unity/Mono so I’m not using VS there.
  2. I know resharper is popular inside the IDE whilst you’re writing code, and I had focused myself on tools downstream (i.e. after I check-in the code, build is automated that has tasks calling out to run unit tests and then things like sonarqube for code analysis).
  3. A lot of what resharper brings is (as far as internet comments go) being showcased in VS2017’s own improved code analysis engine (improvements in intellisense anyway).

Things going in its favor include:

  • Pricing model of resharper is a LOT more reasonable to me than Sonar’s C++ license though. And it may be good enough to catch the things I need it to from slipping through.
  • 30 days should give me some time to try out getting it run from the command line and seeing what it can do there, hopefully it can work with Unity code outside of the IDE too.
  • Given who makes it, even though I am preferring to use Bamboo for build automation at the moment, I am also needing to have a TeamCity installation, so I can hope there are some good task runners in that to further help with the automation and reporting. This would also alleviate my development on the Mac as I can have the build checked out and tested/run on Windows under VS.

Have you had a chance to use it in an automated fashion at all yourself, or do you just let it advise you live in the IDE?

Sorry, I’ve only used it within the IDE so far =/ and I agree that most of it functionalities has been showcased in the VS2017, although in my opinion, it is still worth to use it for the price, even more for unity users since there is a pretty useful extension.

1 Like

Yes it looks promising, thank you for diverting my attention for it. The live IDE thing probably won’t be a deal breaker either in this case, I think it’s more just a change of discipline than it is a limitation.

Also with respect to Unity dev on the Mac, I forgot about this little icon on my machine:

Which paves the way for using it there, regardless of other options (i.e. how much VS2017 is actually VS2017 on the Mac and not just Xamarin Studio functionality with a new name):

JetBrains Unity Plugin
Resharper Unity @ github
R# community: How can I use Resharper with Unity3D on Mac

1 Like

You are welcome!

Good to know about Rider, let us know your opinion about it if you try the Unity plugin from JetBrains =D

I would like to suggest you this article


It should work with unity as well:

PVS-studio is free for non-comertial projects:

2 Likes

In addition to the provided articles, I would like to suggest another one:

Static Analysis as Part of the Development Process in Unreal Engine

1 Like

I think PVS-Studio is one to bookmark for future.

Looks great but I don’t feel their business model is aimed at my segment (their prerogative, that’s ok). You’d have to be either a freeware creator or an indie with significant funding to afford the ongoing renewals.

So the breaking-out self-funded indie needs to look elsewhere. Just as I might expect to be looking at a fiat 500 to drive around and accept that the bugatti is off-limits for a while.

All of the information and replies in this thread though have been awesome for uncovering things I hadn’t yet found.

Btw - I’m not against buying tools, but I’m being necessarily cautious with the budget. Some freemium model tools (for other things not just static analysis) have been an absolute steal, others like the resharper suite start to hit the edge of what can be justified as costs currently, and so I’m mostly operating within that range for now.

1 Like

PVS-Studio team gives an opportunity to use static code analyzer for free, for educational purposes, so that individual developers and enthusiastic teams could also fully use it.

How to use PVS-Studio for Free

1 Like

Thank you @AlexAstva, that’s useful to know and I think re-opens this tool as a valid choice to consider for the indies of this community operating on small-to-no budgets.

@Kirill_Vostretsov Perhaps you might edit your comment for the same article link, as it appears that it can be applied to (limited) commercial development too, not just “non-commercial” uses.

And so the choice of tools for another category (testing and code coverage) starts to take shape nicely. Need to put a few of them through their paces before deciding though, and that’s going to take a while.

Hi,
Did you continue with your research? I’m looking for Unity static code analyzer with easy integration to CI.
I’m trying to analyze Unity project with SonarCloud (which is used to be my default choice for a few years ), but it doesn’t work…

thanks, Vitaly

I was out of town sorry.

In the end I’ve settled on using Rider (and with my VS projects, Resharper) for all SCA needs.

Rider has grown to be a fantastic tool for Unity code development.

Furthermore, Rider now also covers Unreal development too.

Until recently, it was shipping as a separate product (Rider for Unreal) but as of the last Rider release, they’re now joined into one product.

P.s. I realize this isn’t integrated with CI/CD solutions like sonarqube etc., but honestly for me, addressing SCA issues even prior to commit/push/merge has not been a disadvantage and results in cleaner code commits and diffs.

Many thanks! I’ll try it.

Oops - it’s IDE, not SaaS.
Thank you anyway!

Privacy & Terms