20 April ’18 – Dev Blog #6: Moving to Unity 2018

Martin Isla

After doing some testing and spending a few hours doing my research, this week I decided it was time to move to Unity 2018.

This is a -sort of- technical post aimed at developers!

“But it’s still in beta!”

I know that and guess what – we’re in beta too! Actually, we’re in pre-alpha, so it’s not a bad idea at all to move to Unity 2018 and I knew we were going to do so sooner or later, so why not do it sooner?

Since Unity 2018 was announced and I started understanding what the new features were about, I immediately loved it. The scriptable render pipelines, the C# Job System, the performance upgrades. Nothing to hate about this new Unity version. I was so excited to try out these new features!

I talked a bit about it on Twitter (Warning: spoilers ahead), but wanted to expand a little more so other adventurous game devs out there willing to explore new lands (or features) know what to be prepared for.

But if there’s something I learned in my short (but rich) game dev career is: stick to a Unity version!
It’s something everybody tells you. Choose your Unity version and stick to it. It’s usually time-wasting and project-breaking to upgrade to a newer version. But then again, I was so excited to try out the new features, I couldn’t even wait for the beta to be over.

I created a local back up of my project and launched Unity 2018.1.0b13. As soon as I opened The Worst Grim Reaper -for no one’s surprise- a zillion errors immediately filled up my console window. Reading one of those errors, I realized it was TextMesh Pro. After 2 seconds of googling, I found out the older version was no longer supported in Unity 2018.

Unity’s Package Manager

Luckily, I also found out there’s a thing called the Package Manager, which is great. It adds modularity to Unity without the need to download packages from the Asset Store (downloading official packages that should be native always felt a bit weird to me). This is cool because it’s some sort of the middle point: you get native packages without being forced to download them with the editor. Moreover, if a package needs to be updated, you don’t need to update the entire editor, just the package.  Thank you.

Following the instructions in this post (sort of – I suck at following instructions!), I updated to the new, compatible version of TextMesh Pro and no further changes were needed. Everything was working again, I could even run and play!

Perfect: updating to Unity 2018 wasn’t as painful as I expected. But hey, I like to suffer! I wouldn’t be a game dev otherwise. So let’s give the feature I was most excited about a try.

The Scriptable Render Pipeline

Disclaimer: I’m not a graphics programmer. I have no idea what I’m talking about here.

This feature is probably the #1 reason why I wanted to play with Unity 2018. I saw the Unity GDC talk about it and it sounded exciting.

As you might know, The Worst Grim Reaper is a 2D game, but it uses dynamic lighting to achieve more appealing visuals. Using dynamic lighting means the Sprites Shader isn’t enough because it doesn’t accept normal maps. Therefore, we had to use the much over-complex Standard shader. That, combined with Mark Lohmann’s passion for overusing real-time lighting… The Worst Performance1. But there’s so much in that shader we don’t need, we just want simple lighting – no weird PBR stuff, no shadows.

And our dreams came true thanks to 🌈The Lightweight Render Pipeline🌈.

Again, importing the Lightweight pipeline was super easy with the Package Manager. The painful part came later.

Thanks to some really nice person at Unity, a tool is shipped with the Lightweight pipeline package that allows to automatically change every material’s shader from Standard to Lightweight Standard (with PBR). However, that tool doesn’t work with custom shaders. Basically, because pre-existing shaders don’t work with the SRP -custom shaders need to be written for each pipeline-. Lucky for us, we only used one of those, and I’ll talk about it and why we don’t need it anymore.

As I mentioned before, we had to use the Standard shader because the default Sprites shader doesn’t support normal maps (and, therefore, no control over how light affects a sprite!). The problem is sprites can only be seen from one side, so if you flip a sprite that uses the standard shader, it’s gone!

Lohmann had fixed this problem before for his Dynamic Lights video (where we met) by creating every animation twice, and two animations for each state: one looking left, one looking right. You should’ve seen that animator controller. I almost had a stroke.

Actually, let me share the horror with you:

Yup.

There must be a better way to do this, I said when I saw that. And there was. We shamelessly stole the shader from this post, which basically renders the sprite twice.

But now that shader was useless! How are we gonna do this! I started to panic. I loved the lightweight pipeline so much and I couldn’t use it because I have almost no idea how to write a shader. But then, a magic check-box appeared in the material inspector.

Two-Sided just beat Cellar Door

I clicked it and yes! I could flip Sebas without weird shaders!

Finally, after about one hour of having lots of fun, The Worst Grim Reaper worked in Unity 2018.1.0b13 using the Lightweight pipeline just as it worked in Unity 2017.

So, now…

The moment of truth

It was finally time to test the results. Was all this pain finally worth it? I disabled VSync, launched Fraps and compiled the game using both Unity 2017 and Unity 2018.

I’ll go straight to the results. Framerate is in the top-left corner. Click the image to see a full res!

Unity 2017

Average framerate: 250 FPS

Unity 2018

Average framerate: 560 FPS

 

Final words

Upgrading to Unity 2018.1 was, without a doubt, a good idea. Getting over two times the frame rate with no noticeable quality loss and very little work is priceless. However, albeit amazing -can’t wait for you to play it- The Worst Grim Reaper’s code isn’t a super weird or complex thing. The upgrade was easy because we rely on nearly no external code (except for Wwise, which did get a few errors after upgrading but was a super easy fix).

I think Unity is doing a great job with 2018. The Scriptable Render Pipelines allow huge control over the graphics quality of your game, the C# Job System (which I didn’t really need to use yet) is really good for heavy-load tasks (I recommend watching this video which demonstrates the power of this feature), the visual shaders scripting (Shader Graph)… I really hope I need to use it soon!

Well done, Unity. Keep it up!

 

If you want to stay informed about The Worst Grim Reaper, please visit our home page, where you can subscribe to our e-mail list (we don’t spam!) and follow us on Twitter, Facebook or Instagram!

  1. Sorry

2 Comments

  1. Hey, you should try just flipping the sprite, instead of rendering it twice (because that is what you are doing – two sided means the sprite is always rendered twice). To flip the sprite just set the appropriate scale variable in the Transform component (X or Z depending on your game) to -1.

    • Martin Isla
      Martin Isla

      June 5, 2018 at 7:27 pm

      I just saw this, never expected to have a comment here. The problem is flipping sprites with normal maps doesn’t work (you can try by yourself!), the sprite disappears. Two-sided is needed in order to get that working.

Leave a Reply

Your email address will not be published.

*

© 2019 Moon Moon Moon

Theme by Anders NorenUp ↑

%d bloggers like this: