Ported my game to Unity 2017.2. Pretty ok for the most part. The editor itself hasn’t crashed yet, despite what I hear about other people’s experience with 2017.x.
But I did need to change quite a bit of stuff to keep the framerate the same as before.
________
Horizontal Layout Group and Vertical Layout Group is slowThere were at least, no cryptic compile errors. But testing the game, first thing I noticed was a big decrease in framerate. I was getting about less than 20 fps whereas I got around 30-50 fps back in Unity 5.5.5.
Take note this is the fps inside the Unity Editor though. Standalone builds always have higher framerate values, regardless if it was done in Unity 5.5.5 or 2017.2.
But having less than 20 fps inside the Unity Editor was too much. So I suspect something was wrong.
Firing up the profiler showed me the problem:
A lot of calculations being made with rebuilding the GUI layout. I’m not entirely sure why, in Unity 5.5.5, I was not having this problem.
Using process of elimination (disabling GameObjects until the framerate gets high enough), I pinpointed the problem to the enemy healthbars. I had about 20 enemies in my test scene, so that was 20 enemy healthbars.
In this healthbar I had number values of their health and stamina, positioned using Horizontal Layout Group.
I had those numbers disabled (their GameObjects were disabled) because I decided it made the GUI too “noisy” to show a bunch of numbers on-screen anyway. So I was wondering why Unity 2017.2 was calculating them even though they were not visible.
Furthermore, not all 20 healthbars were being displayed at the same time. Most of the time, only the healthbar of the enemy you targeted will show up.
I do remember a Unite presentation telling me Layout Groups were slow. I’m just confused why the Unity 5.5.5 version of my game was not suffering badly compared to now.
(GUI part of this talk starts at 23:29)
I’m not inclined to wonder too much about this. So for now, I simply disabled the Horizontal Layout Group component itself.
That pretty much fixed the framerate problem during gameplay.
________
Alpha Channel not importingWhen I went to the in-game menu, I got this:
I don’t know why I was getting white squares there. Looking at the sprites involved, I found out Unity 2017.2 is not able to import the alpha channel of some .psd files properly anymore.
In Unity, the image looked like this, (see the preview, showing it completely white):
In Photoshop, it looks like this (see the checkered background indicating transparency):
Not all of the .psd files were having this problem. So I just worked around it for now by exporting the affected .psd files into .png files and using those.
However, this should probably not be happening in the first place, so I’m guessing it’s a regression bug.
________
Unity UI TextMy other problem was a big slowdown in framerate whenever I enter the in-game menu.
The profiler again, pinpointed the problem:
About 9 MB was incidentally being allocated per-frame by this NicerOutline script I was using. This was from the Unity UI Extensions I was using, to give some outlining effect to the Unity UI Text.
I had them in all of my UI Text, so going to a screen with a lot of text slowed down the game (like the Graphics Settings Screen).
This is how text effects (drop shadow, outline, gradient, etc.) are done in the standard Unity UI Text component. They are individual scripts. NicerOutline being one of them that I have in my project.
I’ll just clarify that I’m using an old version of Unity UI Extensions that I haven’t bothered updating, so maybe they have fixed that now.
However, the thing is I’ve since upgraded to using TextMesh Pro (ever since it became free), and TextMesh Pro doesn’t have this problem. It also has a bunch of other features that make it superior to the standard UI Text (crispier looking font, built-in letter spacing, etc.)
Text effects in TextMesh Pro are done in a dedicated shader, specifically built for it. It’s fast since effects are done entirely in the GPU, instead of C# scripts.
But since replacing all of my UI Text into TextMesh Pro was a very boring thing to do (I had a lot of Text in many screens), I hadn’t done it yet, and I kept holding off that task since it didn’t seem to affect the game that badly (until now).
So for a long time, only some parts of the GUI was using TextMesh Pro, while the rest was still doing it the old way, with the standard Unity UI Text plus the NicerOutline script.
Obviously I can’t keep using that; it was slowing down the game. I decided it was better to go ahead and finally go with TextMesh Pro all the way.
________
Cloth Simulation and AIAnd with that, the game’s framerate was generally better. Some things are still taking a big chunk out of the total frame time, but they do not affect the framerate badly.
The cloth simulation takes a big chunk (the highlighted orange part), since all characters in the test scene are using cloth simulation. I really can’t do anything about the code for that since that’s PhysX.
The most I could probably do is forcibly turn off cloth simulation for characters that are either too far away and/or obscured by walls. Certainly something worth trying later on.
And occasionally, my AI system. Every now and then, all enemies do some raycasts, overlap sphere checks, simple distance checks, etc. to detect if the player/hostile character or some breakable obstacle is nearby.
But again, both of those are not affecting the framerate that badly, compared to the other problems I mentioned. So I decided not to do anything about them.
Just note that those screenshots of the profiler indicate an average of 30 fps because the profiler itself can slow things down a little. When I close the profiler, the Unity Editor can get something like 40 fps on average (and something like 50+ fps if the camera is not showing any enemy on-screen).
And again, like I mentioned earlier, a standalone build of the game will get an even higher amount of framerate.
________
3rd-party PluginsUpdating from Unity 5.5.5 to 2017.2 was quite a big jump, so I naturally expected I have to update a lot of the plugins I use (TextMesh Pro included): Editor Console Pro (better console log window), Rainbow Folders (customizable folder icons in Unity’s project window), InControl (customizable control bindings for the game), Shader Forge (visual shader editor).
If you’re doing an upgrade like that, just be sure to check the plugin’s readme in case you need to do something extra to make sure it updates properly. Usually you need to completely delete the plugin’s folder and import the new version, to ensure no undesired files remain. Just don’t accidentally delete your user preferences for those plugins, if they have any.
In TextMesh Pro for example, I made a separate folder called “TMP User” and moved the TMP Settings file, all the color gradient presets, etc. into that. Those are files that I’ve already edited to suit my tastes, so I don’t want them to get overwritten whenever I update TextMesh Pro.
________
All in all, upgrading to Unity 2017.2 went smoothly. I think I’ll keep using this unless I see some showstopper bug (i.e. the Unity Editor crashing).