Scaleform for Unity - Evaluation, Problems, Thoughts
This new blog post has been written by Sergej. He’s one of the founder of the Bit Barons and he’s going to implement the technical side of Tridek’s graphical user interface (GUI). For this Sergej evaluated the Scaleform plugin for Unity. Like our last post, this one is also rather technical and mostly aimed at our fellow Unity developers who might want to try out a new tech for their GUI needs. But now let’s hear what Sergej has to say about Scaleform:
After gaining some experience with game development on mobile platforms like iOS and Android, I’ve got to say that dealing with images and resolutions on different devices is a big pain in the ass. Controlling image size and compression artifacts are the most time-extensive parts of my job. As you can imagine, the fragmentation of devices with different resolutions and aspect ratios on Android leads to many problems: designing the GUI is much more difficult than on iOS - last but not least due to the scaling image artifacts. To avoid all this stuff, we’ve decided to use vectors instead of pixel-based images.
Vectors and Unity
The problem here is that Unity does not render vectors. Well, that’s not quite right, because there are some plugins that can do that. The first plugin for this was RageSpline. It’s very nice tool that almost perfectly works with Unity - especially with the RageTools extension - but it also has some weak points. I’ll not go into the details here, but after some evaluation I knew that RageSpline was good as a fallback but not good enough to start the development with it.
The solution to our problem then came very quickly. Directly after evaluating RageSpline a long-awaited message arrived in the Unity community: Autodesk finally announced its Scaleform plugin for the Unity engine.
Scaleform for Unity: Pros and Contras
After registration and download, the plugin waited to be evaluated. But before starting the tests, we had to think about the pro and contra of Scaleform. The obvious pro arguments are their long experience in the market, the well-known performance you can see in other products using Scaleform, the ability to animate in Adobe Flash instead using the Unity Animation Editor, very simple font embedding, localization and aspect ratio management. On the other side we had contra arguments like its unknown behavior on different platforms (performance, glitches and limitations), learning and using another language (ActionScript 3), using the bridge between C# and AS3, the price of the Scaleform license and many others unknowns because of lack of experience using Scaleform.
To try out all features of Scaleform we started with a “one day” game jam. The main goal was to understand the workflow of Scaleform in combination with Unity. Our first issue was the communication between C# and AS3. In Scaleform you can send invokes from AS3 to C# and vice versa. All worked fine until we tried to get invoke from AS3 and send another one from C# to AS3, which one called another function back in C#. All this inside one frame update. The problem was that the last function call got lost! After some research we found out that the plugin is checking the invoke queue and is not capable to add another one on top while in the same frame update. Until the Autodesk team fixes this behavior my advice is to use as little invokes in one frame as possible. The second issue was the lack of a good way to load an image from outside of Scaleform. The Loader class is functional on iOS but it was not possible to load an image on Android platform. Also it’s not possible to load an image from Unity in Scaleform. This one was a shock for us because it is essential for our project. We will have so many different cards in Tridek that we don’t want to update the whole application any time we add a bunch of new cards graphics.
After the first steps and some bad news we had to find a workaround for the image loading problem. That was more difficult than expected. First we’ve tried to load the images from outside the application using the Loader class. As mentioned before, this worked well on iOS but didn’t work well on Android. It took many tries – all of which failed. Next we tried to load images from external .swf Flash file, but that also doesn’t work because the Scaleform doesn’t support loading external classes inside the flash.
Besides this image loading problem a lot of my time was spent on learning to work with Flash (again) and to use the AS3 programming language. I have to admit that this was a quite fun. I like the way Flash animations works. It’s much easier and better to animate here as within Unity’s animation editor. One negative point of Flash is the performance on MacOS. Waiting for five seconds to switch between two AS3 documents – seriously, Adobe?
But back to topic. After spending a few days trying to get my images loading without any success we got good news on the Autodesk Scaleform forum. The SetTexture and Render-to-texture integrations, two very important features of Scaleform, are now the part of the plugin – fixing my problem without me having to change anything. Well at least the time spent trying to load an image over and over again got me up-to-date with Flash and AS3 again quickly.
Conclusion and final thoughts
The first and most important question of the evaluation was if Scaleform is capable to deliver the performance and all the features we need in Tridek. After many headaches and doubts I can definitely say yes to that!
The other question was its the behavior on different platforms. Scaleform worked very well on both Android and iOS. Android was much easier to setup, because the only thing you have to do is to build the project in Unity - and that’s it. For iOS it’s more difficult because setting twenty different parameters in XCode can be very annoying. But anyway, Scaleform delivers good performance on both systems. But it should be noted that Scaleform needs an ARM7 CPU. So it doesn’t support older ARM6 Android devices and older iPhone generations like 2G and 3G.
Learning AS3 was more fun than what I expected. But of course the language is not as powerful as C# and the like. The design of AS3 in Flash is a little bit weird because it’s a composition between a visual timeline and a programming language - but after a while you get into it and there is no problem anymore. Also the bridge between ActionScript and C# worked very well besides of the aforementioned invoke problem.
Concluding I have to say that Scaleform is a very powerful tool and a big improvement of Unity as a game engine. The possibility to use Flash for GUI and even as a complete 2D engine inside Unity on mobile devices - where images size and memory usage management are very important - makes Scaleform an essential part of the Engine. We’re definitely going to use this piece of technology in the creation of Tridek.