My first 24 hours with Unity 5

I've been anticipating the release of Unity 5 since I attended the Unite '14 conference in Seattle, but not for the same reasons as many people.  The most talked about new features in Unity 5 are the new physically based shading and lighting systems.  While those look great (that Blacksmith demo was gorgeous), they don't really apply to what I'm doing.  The update to PhysX 3.3, though, is of great interest to me.  So yesterday, about 5 minutes into the release announcement, I started the download.  Here's the story of my first 24 hours of upgrading When Pigs Fly to Unity 5.

Initial Experience

I started out by upgrading a couple old Ludum Dare projects to test the waters.  Both of them worked perfectly with no modifications from me.  With my confidence bolstered, I began the upgrade process for When Pigs Fly (after making a back up copy, of course).  After a couple minutes, the editor opened up and everything seemed to be right where I left it.  Feeling good, I pressed play and this is what I saw.

Dismayed, I clicked back to build mode, and all of my menus were blank.  I tried loading up a different plane.  This one didn't explode, but the wheels went right through the ground.  When Pigs Fly was not going to upgrade as smoothly as my test projects.

The Easy Fixes

All of the menus being blank was making it difficult to test other systems, so I set out to fix that problem first.  I'm calling this an easy fix, and it was, but it still took me three hours to figure out. 

The two menus in question are the parts list and load menu.  They both work by instantiating button prefabs for each part or plane, then parenting those prefabs to grid layout groups in the menu.  I could see in the hierarchy that the buttons were indeed being instantiated and parented to the correct menus.  Their transforms showed the correct positions and sizes, and when I clicked to focus on the buttons in the editor, the camera panned to where they should be.  But they were all invisible.  

I spent a long time playing with the settings of the grid layout group with no success.  Then I fiddled with the canvas settings, then the renderers.  Nothing.  Finally I pressed play, then manually created a button and parented it the group. It immediately snapped into place.  I took a look at my code, and saw that I was doing the instantiation and parenting in Awake().  I changed that to Start(), and bam, everything back to normal.  When I think about it, it makes perfect sense why this wasn't working.  I don't know why it worked in 4.6, but it did.  Maybe the script execution order changed in the upgrade, I don't know.  But as a general rule, this type of thing should be done in Start() or later.

The Easy but kind of Annoying Fixes

Next up on the list was exploding planes.  I tried several different designs and got several different results.  Some exploded as seen above, some simply fell apart, and some were absolutely fine.  My first hunch was that I was instantiating overlapping colliders.  Sure enough, I found that some of my parts had colliders that were just a touch (like 0.05 units) bigger than they should have been.  I guess the earlier version of PhysX was more tolerant of this, because it wasn't a problem in 4.6.  Anyway, I tweaked the colliders on those parts and went back to the tests.  The planes that were simply falling apart before now fell apart more slowly, and the planes that were exploding were still exploding.  I went to the physics settings to try changing the max penetration for penalty property, but that is no longer available with PhysX 3.3.

My next thought was to try increasing the break force on the joints.  In 4.6 it was set at about 300 for most parts.  I kept increasing and increasing until I settled at around 45,000 for similar results.  I don't know if the PhysX update changed the units of measurement for this property or something else is wrong, but with break force set at 45,000 the planes that were falling apart previously were now working correctly.  The exploding planes, however, continued to explode.

After testing a few more designs, it dawned on me that all of the exploding planes had moving parts.  The main difference in the setup of the configurable joint on a moving parts (other than the movement, obviously), was that I had enabled projection. Projection was necessary for stable moving joints in 4.6, but in 5.0, any build with a single projection enabled part instantly exploded.  I disabled it, and everything was back to normal.  The joint stability seems improved in 5.0, so projection doesn't seem necessary anyway.

Ongoing Problems

I still haven't been able to get wheel colliders to collide with anything.  I thought maybe there was a layer problem, but couldn't find one.  Perhaps there was a problem with mesh colliders (used for the terrain), so I tried putting a big box collider under the plane.  Still no luck.  I deleted the entire wheel prefab and rebuilt it from scratch without success.  I was kind of starting to lose my mind on this one, so I put a pin in it (replaced them with sphere colliders) and will come back to it once everything else is sorted out.

There doesn't seem to be a way to get the new standard shader to use vertex colors.  Almost everything in When Pigs Fly is vertex colored, so I can't use the standard shader and its fancy new PBR.  I also haven't been successful in getting the new global illumination systems to do anything with my own shaders.  The only graphical change I've made so far in When Pigs Fly Unity 5 is the new procedural skyboxes.  They're really cool, but I'm not sure how well they fit with the style of my game.

Performance has been an issue as well.  Unity 5 was supposed to perform better all around, and the upgrade to PhysX 3.3 reportedly improved performance by 2x.  So far, though, the performance of When Pigs Fly has actually been very slightly worse in 5.0 than it was in 4.6.  Its very possible that this is my fault, maybe I'm doing something in a way that doesn't jive well with the new system, but I am a little disappointed that my physics heavy game has seen no improvement from the upgrade.

One strange note: in 4.6 the clouds in my game had zero noticeable impact on performance.  In 5.0, disabling the clouds consistently increases the framerate by 10 FPS.  Not sure what's going on there.

Enough with the Doom and Gloom

Reading back over what I've written here, it would seem that my upgrade experience hasn't been very good at all.  But that isn't the case.  I feel very happy with Unity 5.  There are still many new systems that I haven't fiddled with yet.  I'm looking forward to exploring the new audio mixers.  Now that all engine features are free, I know the profiler will prove invaluable in tracking down performance issues (like why I'm not seeing any physics improvements!).  I'm also happy to have the LOD system, which I plan to use to greatly increase the draw distance of the terrain.  There are bound to be hiccups with the release of any software update this big.  I'm mostly back on track one day later, and that's pretty good.  Now if I could just stop playing with the newly free image effects and get back to business, everything will be great.