[Released] Animated GIF Player

Hi everyone,

I have just released Animated GIF Player which allows you, as you might guess, to play animated GIFs in Unity. Usage is very simple. Just add the Animated GIF Player component to an object and select a GIF that was copied to your StreamingAssets folder. Example usage:

Key features:

  • Easy to use with no scripting required
  • GIFs are decoded in a separate thread for increased performance and can be buffered and/or cached if needed
  • Pure C# solution, no installation of extra plugins or editing to get everything to work on mobile
  • Includes commented source code
  • Great for short videoclips as a replacement for MovieTexture on mobile. For example short tutorial movies or in-game television screens. Just convert your movie clip to an animated GIF using one of the many free online tools available.
  • Works on all platforms. Should you encounter any problem despite this, please let us know and we will fix it right away).

Link: Unity Asset Store - The Best Assets for Game Making

Updates:

  • V1.14.0

  • Bug fixes

  • Added compatibility mode to allow playback of a wider range of GIFs. This includes GIFs that use the previously unsupported (but rarely used) “restore to previous” disposal method

  • V1.13.5

  • Fixed looping when using the threaded decoder and caching frames

  • V1.13.4

  • Fixed a potential memory leak when changing caching settings during run time

  • V1.13.3

  • Fixed crash when reloading a GIF when using the threaded decoder

  • V1.13.2

  • Fixed crash when switching GIF images if the first image wasn’t done loading

  • V1.13.1

  • Fixed Android builds on Unity 2017.2 and higher

  • Fixed tmp texture not being destroyed when loading a new gif with the same Animated Gif Player component

  • V1.13

  • Fixed issue with Gif files not loading when using the Unity editor on Mac Os

  • Fixed bug where in some cases the first frame of the Gif was incorrect

  • Sprites are no longer resized after starting Gif playback on them

  • Gif target sprites are created as full rect instead of tight mesh

  • Gif target textures are no longer created twice. This should improve startup performance somewhat for large Gifs

  • V1.12

  • Gifs can now be loaded from: Application.streamingAssetsPath, Application.persistentDataPath, Application.temporaryCachePath as well as http

  • V1.11

  • Added speed controls which allows changing playback speed independent of Time.timeScale

  • V1.1

  • Changed namespace to “OldMoatGames”. If you are updating change “using AnimatedGifPlayer;” to “using OldMoatGames;” in your code

  • Can load GIFs from web instead of just StreamingAssetsFolder. This feature can only be used from code. See the code example scene for more info

  • Fixed the duration of the visibility of the first frame when resuming playback with the Play() method

  • Added OnLoadError event

  • Added Width and Height vars that return the size of the GIF once loaded

  • V1.02

  • Fixed playback on WebGL

  • V1.01

  • Bug fixes

  • V1.00

  • First release

2 Likes

Hello,
Instant purchase. Working great on editor, but when I try building for Android, it gives me an error:

Assets/AnimatedGifPlayer/Scripts/AnimatedGifPlayer.cs(450,55): error CS1061: Type AnimatedGifPlayer.GifDecoder.GifFrame' does not contain a definition for delay’ and no extension method delay' of type AnimatedGifPlayer.GifDecoder.GifFrame’ could be found. Are you missing an assembly reference?

EDIT: Found the problem. Maybe you’ve made a case mistake (but I’m not sure). Replaced ‘.delay’ with ‘.Delay’ and seems like it’s fixed…

EDIT2: Doesn’t work on Android :confused: Didn’t test iOS yet.

I have uploaded a new version (1.01) to the asset store that fixes the bugs you are experiencing. The package needs to be approved first though. Since this can take some time and you will probably want to be able to use the gif player, these are the changes that you can make to file AnimatedGifPlayer.cs in order to fix the bugs yourself:

In AnimatedGifPlayer.cs:

Line 254:
Change

var path = Path.Combine("file:///" + Application.streamingAssetsPath, FileName);

To:

#if UNITY_ANDROID && !UNITY_EDITOR
            var path = Path.Combine(Application.streamingAssetsPath, Uri.EscapeUriString(FileName));
#else
            var path = Path.Combine("file:///" + Application.streamingAssetsPath, Uri.EscapeUriString(FileName));
#endif

Line 450:

_nextFrameTime = Time.time + CurrentFrame.delay;

To:

_nextFrameTime = Time.time + CurrentFrame.Delay;

The bugs were caused by some last minute changes I made before submitting the first release and forgetting that spaces in filenames are handled differently on iOS and Android than on the Windows editor.

Sorry for the inconvenience. If you run into any more problems or have any questions or requests please let me know!

Thanks for the quick update but sadly, still doesn’t work on mobile. Tried replacing the code, but nope :confused:

I have updated the above code to fix that. Tested on both Android and iOS as working

Working now, thanks!

A new update has been released which fixes playback on WebGL.

A new update has been released:
V1.1:

  • Changed namespace to “OldMoatGames”. If you are updating from 1.0 change “using AnimatedGifPlayer;” to “using OldMoatGames;” in your code
  • Can load GIFs from web instead of just StreamingAssetsFolder. Only usable from code. See the code example scene for more info
  • Fixed the duration of the visibility of the first frame when resuming playback with the Play() method
  • Added OnLoadError event
  • Added Width and Height vars that return the size of the GIF once loaded

Hello, looks awesome your plugin :slight_smile:

But I´m having a problem playing in a RawImage.

I have a RawImage inside a gameobject, if I try to activate the parent gameobject some Gifs works, and others doesn´t work…

Attach Gifs working (60fps.gif) and gifs not working (Photoshop.gif).

Best regards

3073589--231125--60fps.gif
3073589--231126--Photoshop.gif

Hi,

Both GIFs work if I use them in the ui example that is included with the asset (This is in the editor on windows). Could you be more specific about when they don’t work (are you playing the gif from code or are you just using the inspector for example)?

UPDATED: I found the problem. The problem was that I set:

Time.timeScale = 0;

Do you think It would be a good idea add an option in the script in order to avoid the TimeScale when is playing Gif?

Thanks!
Best Regards.

Glad you found the cause :).

You mean an option that allows playback to continue when timescale is set to 0?

The GIF player uses Time.deltaTime to determine when a new frame should be played. This delta time takes the time timescale in consideration. So with lower timescale playback is slower.

I will add an extra option in the next update. For now you can replace the function called UpdateFrameTime around line 491 to 509 in the script AnimatedGifPlayer.cs with the following code:

private void UpdateFrameTime() {
   if (State != GifPlayerState.Playing) return; // Not playing
   _secondsTillNextFrame -= Time.realtimeSinceStartup - _editorPreviousUpdateTime;
   _editorPreviousUpdateTime = Time.realtimeSinceStartup;
}

With this change timescale has no effect anymore on playback speed

Thanks for reply Mareck :slight_smile:

Ok, I have fixed avoiding the set timescale to 0 when I show tutorial gif.
But yes , it will be an awesome new feature the option to activate or desactivate timescale effect :slight_smile:

Best regards

Hi.
Does it work properly with transparent gif?
like this 3105320--234588--animated-dinosaur-image-0033.gif
If i assign this gif to a plane can I see Objects in back of this plane(where the opacity is zero on gif)?

Hi,

It sure does work with transparent Gifs.

3107464--234818--transparent-animated-gif-player.PNG

To get this I used the MeshRenderer example that is included. Just create a new material and set the rendering mode of that material to transparent. Then go to the GifTexture object, select the mesh renderer and replace the default-material with this new material.

I purchased it and works perfect . Sprite Example is exactly what I want.
Thanks

Version 1.11 has been released.

In this version speed controls have been added that allow changing the playback speed of the Gif. The speed is relative to the normal speed as encoded in the Gif. So, for example, setting it to 2.0 will double the playback speed.

Also note that the gif player will not try to catch up if the fps of the game are lower than the playback speed of the gif. In other words: even when the playback speed is very high, the player will not go faster than the fps of the game. No frames are ever skipped.

Version 1.12 was just released. This update adds an option (code only) to also use persistentDataPath and temporaryCachePath instead of just streamingAssetsPath.

Hi Mareck
I just got the asset and every time I select a gif of my own I got an error.
I was wondering is there anything wrong with my gif?

ArgumentNullException: Argument cannot be null.
Parameter name: buffer
System.IO.MemoryStream…ctor (System.Byte[ ] buffer) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/MemoryStream.cs:80)
(wrapper remoting-invoke-with-check) System.IO.MemoryStream:.ctor (byte[ ])
OldMoatGames.AnimatedGifPlayer+c__Iterator0.MoveNext () (at Assets/AnimatedGifPlayer/Scripts/AnimatedGifPlayer.cs:339)
OldMoatGames.AnimatedGifPlayer.Init () (at Assets/AnimatedGifPlayer/Scripts/AnimatedGifPlayer.cs:242)
AnimatedGifPlayerEditor.OnEnable () (at Assets/AnimatedGifPlayer/Editor/AnimatedGifPlayerEditor.cs:17)
3154787--239888--Fly.gif

Does this also happen when you select one of the included gifs? Also, what version of Unity are you using?