Developer Insights

Report from the trenches by Unity 3D game developer using GAF

 

Developer: LTD Scientific Endeavors
Location: Russia
Game Title: Scifun Steve in SciLand
Game Genre: Education
Framework: Unity3D

Using frame animation in Unity3D

As soon as the new animation is created, the link to the animation component SpriteRenderer appears. Unity then prompts the user to drag the frames to the animation window.

Frame animation with GAF in Unity3D

A few mouse clicks and the new animation is in your scene!   The goal for a one second clip is about 15-20 frames. But what if the character includes many different movements such as run, plant, water plants, play, get a suntan, etc.  The resulting duration of the animation would end up being many seconds and possibly a thousand frames. This was indeed our case. Although we had a simple scene, it took more than a minute to load and Unity started to crash because of the RAM exhaustion.  We tried using the built-in Unity SpritePacker to pack sprites in atlases but that resulted in an insignificant 10-20% performance improvement.

gaf, convert flash to unity to get an insignificant perfomance improvement

Possibility of replacing frame animation with skeletal animation

To achieve more significant results, one option would have been to change from frame animation to skeletal animation. Instead of sprites we would have to go to a more complicated pattern (model) with the character drawn from parts of the atlas.

To achieve significant result from frame animation to skeletal animation

And in order to get the animation to work using the skeletal model we would have had to consider using skeletal 2d animation tools for Unity such  as: Spine, DragonBones, Anima2D, etc.

But our artist had already created all the animations in Flash.  Upon further ​research we discoverd the GAF Converter Plugin in the Unity Store, and found it to be the best solution to greatly reduce frames and solve our crashing problem.

 

Importing animations from Flash to Unity with GAF Converter Plugin.


Here's a summary of how we did this.

 

  1. Import GAF from the Unity AssetStore.

  2. Drag file *.swf into the converter window.

  3. Create an object and customize it. All the settings are intuitive:​

 

Settings in GAF plugin in Unity3D

 

The animations were created automatically by the markup contained in Flash.

 

 

To run the necessary animation using scripting:

 

using UnityEngine;
using GAF.Core;//
Use the space of GAF names

public class Mouse : MonoBehaviour
{
 //
Declare and mark link in the inspector
 [SerializeField] private GAFMovieClip GAFMovieClip;
 
 void Update ()
 {
   if (Input.GetKeyDown(KeyCode.RightArrow))//
When pressing “right” key
     GAFMovieClip.setSequence("run", true);//Run the clip “run” cyclically
 }
}

 

Configuring transitions in Unity Animator

 

In Pro GAF version there is the option to use the native Unity-animator which makes the development a lot easier. But we needed to keep in mind that our type of animation didn't  support mixing. Unity mixes clips by default. Our animations would distort on transition between clips. So we turned off the mixing of clips to enable our animation to work smoothly:

 
Configuring transitions in Unity Animator with GAF
 

Editing animation clips

 

If it turns out that you didn’t create all the needed clips in Flash you can create them directly in Unity by using the function updateToFrameAnimator() and point at the needed frame.

 
Editing animation clips in Unity with GAF plugin
 

Results using the GAF Plugin for Unity

 

The new animations created by using GAF reduced the time to load the scenes by 10X! In addition, RAM consumption was also reduced by about 2X.   We're happy we found the GAF Plugin in the Unity Store!  It really saved us on this project.  

 

Useful links:

 

Video lesson "Using Flash animation in Unity" (In Russian)

GAF: Import Flash animation in Unity3D (In Russian)