Search Unity

[FREE] Moments, a quick GIF replay recorder

Discussion in 'Assets and Asset Store' started by Chman, Apr 19, 2015.

  1. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    Hi there,

    I put another free asset on GitHub, some of you might interested.

    Moments
    is a quick GIF replay recorder for Unity. It automatically records the last few seconds of gameplay and lets you save to a GIF file on demand, like the game TowerFall Ascension does.

    Here's a quick output preview if you're wondering about the visual quality.

    Don't forget to check out the other assets in my signature !

    Enjoy :)
     
  2. Merrik44

    Merrik44

    Joined:
    May 8, 2013
    Posts:
    38
    Rad, Thanks so much!
    Awesome of you to share this for free.

    Quick question:
    Do you know of a way of preventing flicker between frames?
    I assume this is occurring because each frame has its own palette
     
  3. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    That's exactly it.

    There are basically two ways to generate a gif file : use a single palette for all the frames (so 256 colors for the whole duration of the animation, which would result in a very low quality) or use a palette per frame, which is what Moments is doing. It works fine most of the time but it can induce some flickering when a new color is introduced abruptly and removed a few frames later. There are a few ways to fix this (like using the previous palette to generate the new one) but I probably won't have the time to implement it as in its current state it fits my needs.

    But it's open source, so if anyone wants to dig in... ;)
     
  4. nosyrbllewe

    nosyrbllewe

    Joined:
    Oct 18, 2012
    Posts:
    182
    Cool, how long can it record?
     
  5. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    There's no time limit, it depends on the amount of memory you want to allocate. It's not meant for long session recording but for quick replays. This isn't a typical "start / stop" recorder, it constantly records the screen in a fixed size buffer and at any moment you can tell it to dump the last few seconds a gif file. A similar system is used in Towerfall for the kill cam.
     
  6. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Hey Chman,

    This looks excellent, thanks!

    Can this handle multiple cameras? I'd like it to capture all active cameras if possible.
     
  7. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    It should :) Simply put a Recorder component on each camera. Make sure you take a look at the code in the demo !
     
  8. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Wouldn't that generate a different GIF for each camera? I'm hoping for a composite of all cameras just a the game would render.

    It'd be awesome if it could just be added to a scene and it would render all active cameras without the need to know which would be active. I use quite a few cameras but only a 2 or 3 are active at once. That is, I won't know before hand which are the active cameras.
     
  9. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    Well yeah, it will render one gif per camera, it doesn't composite. It depends on you camera setup : are you talking about multiple cameras rendering multiple scene views or multiple camera being composited to screen (using Camera.depth & clear flags) ?

    Add the recorder to the top most camera, the one that displays what the player sees. It will record this camera and what it shows, no need for compositing as it should already be done by your camera setup in Unity :)
     
  10. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Oh really? Sounds good - perhaps I'm just showing my ignorance here.

    I have 1 camera for my UI, many for the scene proper but only one of these active at one time (views from different angles, cut scenes etc) and dynamically created ones for dialogs and bits etc.

    All are composite drawn (yep, with Camera.depth and clear flags) - so if I set it on the topmost camera it'll render everything - I didn't realise that cameras worked like that, cool!!
     
  11. _invalidusername

    _invalidusername

    Joined:
    Jul 1, 2014
    Posts:
    35
    Does this support multiple cameras rendering different layers?
     
  12. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    Nice def think I'll use this.

    hate that 2015 gif is still the only ubiquitous animated file format on the web though.. kinda sad apng never took off its way better.
     
  13. EMOTION-THEORY

    EMOTION-THEORY

    Joined:
    Jul 16, 2013
    Posts:
    83
    Is there any way to also record UI that's layered on top?
     
  14. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    If the Canvas is set to "Screen Space - Camera" or "World Space" then yes, it will be recorded if the script is put on the camera rendering the UI. If it's set to "Screen Space - Overlay" then unfortunately you're out of luck.
     
    abittman likes this.
  15. kbm

    kbm

    Joined:
    Aug 7, 2014
    Posts:
    84
    Hi, is there any way to SAVE the gif during runtime, so the player can record his own gif and save it to Desktop? (Using WebGL Export)

    I already tried serialization for hours, but it seems like Unity only serializes the first frame of the gif, not the rest, so the serialized and then saved file doesn't load the gif.
     
  16. Rithy-Jim

    Rithy-Jim

    Joined:
    Nov 10, 2012
    Posts:
    19
    I try to build the apk to test and the .gif was save but exactly it is still image. I also import the .gif from mobile to computer and it still doesn't play the .gif file. Did this Moment Recorder support on mobile device? I test it in editor and everything was great.
     
  17. MKeff

    MKeff

    Joined:
    Jan 26, 2018
    Posts:
    2

    Hi Everyone,

    This is an awesome tool and feature to have in-game. I've been looking for ways to implement it into a WebGL build, although I've read saving images through the browser can be tricky because of browser security. After some research, I found code that is capable of saving single frame screenshots to the local drive, from a WebGL build.

    here is that link to that code;
    https://forum.unity.com/threads/how...f-the-browser-without-pop-up-blocking.440051/

    I wanted to see if anyone might know if it's possible to combine these various scripts so that the GIF replay recorded using Moments could be saved to the local drive within a Unity WebGL build. I'm very new to coding so I'd be most appreciative to know how or if it's possible.

    thank you,
     
  18. viku_99

    viku_99

    Joined:
    Dec 14, 2016
    Posts:
    11
    Hello i want to record only Half screen of my image and then export to Gif using moment recoerder??
     
  19. ElliotCurtis

    ElliotCurtis

    Joined:
    Nov 26, 2018
    Posts:
    20
    I have been using Moments and it's great- thanks. But it's not creating a gif when running on my phone, only on pc.
    I really don't understand what's wrong and there are no errors being created.
    I guess this is the bit that has the issue:
    private void startGifEncoding() {
    InstructionsText.enabled = false;
    WaitText.enabled = true;
    FBButton.enabled = false;

    GalleryButton.enabled = false;

    _progressBarHolder.SetActive(true);
    ProgressBar.fillAmount = 0;
    _gifRecorder.OnPreProcessingDone += gifDone;
    _gifRecorder.OnFileSaved += gifSaved;
    _gifRecorder.OnFileSaveProgress += progressUpdated;
    _gifRecorder.Save("GamePlayCapture");
    }

    Any help is gratefully received!
     
  20. ElliotCurtis

    ElliotCurtis

    Joined:
    Nov 26, 2018
    Posts:
    20
    Hi Rithy-Jim,
    I am struggling to get this working on mobile too, but it's fine on pc.
    Did you ever get it to work?
     
  21. Immu

    Immu

    Joined:
    Jun 18, 2013
    Posts:
    240
    Quick note for users that import it in latest unity versions, you might want to add
    Code (CSharp):
    1. using MinAttribute = Moments.MinAttribute;
    in MinDrawer.cs
     
  22. pXd-fs

    pXd-fs

    Joined:
    Oct 30, 2014
    Posts:
    3
    Thanks Immu!
    Also using the demo scene (or calling record() manually) I always get "Nothing to save. Maybe you forgot to start the recorder?" did you find a fix for that?
     
  23. pXd-fs

    pXd-fs

    Joined:
    Oct 30, 2014
    Posts:
    3
    @Chman When running the demo scene (or calling record() manually) I always get "Nothing to save. Maybe you forgot to start the recorder?" do you have any idea why it's not recording? It's a vanilla copy from github in Unity 2019.
    Thanks
     
    Blarp likes this.
  24. st_Drunks

    st_Drunks

    Joined:
    Nov 8, 2018
    Posts:
    9
    Did anyone ever find a solution to "Nothing to save. Maybe you forgot to start the recorder?"?
    I've recently moved my project to URP and now I can't get the recorder to work.
     
  25. liamrobertson

    liamrobertson

    Joined:
    Oct 28, 2015
    Posts:
    7
    @st_Drunks @pXd-fs

    Moments is using OnRenderImage(), which is not used in the scriptable render pipelines (e.g. URP). So it will not work.

    There would probably be some way to adjust the code to use an output texture from the camera instead, but I don't know how to do that ¯\_(ツ)_/¯