Forum rules - please read before posting.

Screenshots also include the save menu when using default Unity UI

edited February 2016 in Technical Q&A
I've started fiddling around with showing screenshots in my load menu, which was originally based on the default Unity UI you can choose in the new game wizard.

It seems that the save menu is still active when the screenshot is saved, so you also get a nice picture of the save menu smack in the centre of the screenshot.

This doesn't happen with the AC menu system - I checked with two completely fresh projects based on the new game wizard, one using the default Unity UI and one using AC's system.

Not a huge problem for me right now, but just thought I'd share it here...


Comments

  • AC will temporarily disable it's own menu system while taking a screenshot, but I'm not sure about Unity UI-based ones.  I'll see if this is a bug, or just a missing feature.  Either way, I'll see to it.
  • edited October 2020

    Sorry for bringing this up again. I use AC 1.50f
    I have the same problem using with AC based ones and it looks like UI ones too.
    Display: Label and Screenshot
    Settings: Take screenshot when saving - checked
    Time display: Time and Date

    If it had been dealt with later versions of AC.
    Could you kindly recommend how to fix it in 1.50f
    I know I should have updated AC but I'm too scared to redo my project.

  • Add to Menu.cs:

    private bool isDisabledForScreenshot;
    public void PreScreenshotBackup ()
    {
        if (menuSource != MenuSource.AdventureCreator && RuntimeCanvas)
        {
            isDisabledForScreenshot = RuntimeCanvas.gameObject.activeSelf;
            if (isDisabledForScreenshot)
            {
                RuntimeCanvas.gameObject.SetActive (false);
            }
        }
    }
    
    public void PostScreenshotBackup ()
    {
        if (menuSource != MenuSource.AdventureCreator && RuntimeCanvas)
        {
            if (isDisabledForScreenshot)
            {
                RuntimeCanvas.gameObject.SetActive (true);
            }
        }
    }
    

    Replace SaveSystem.TakeScreenshot coroutine (around line 324) with:

    public bool isTakingSaveScreenshot;
    private IEnumerator TakeScreenshot (string fileName)
    {
        isTakingSaveScreenshot = true;
        KickStarter.stateHandler.PreScreenshotBackup ();
        foreach (Menu menu in PlayerMenus.GetMenus ())
        {
            menu.PreScreenshotBackup ();
        }
    
        yield return new WaitForEndOfFrame ();
    
        Texture2D screenshotTex = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
    
        screenshotTex.ReadPixels (new Rect (0f, 0f, Screen.width, Screen.height), 0, 0);
        screenshotTex.Apply ();
    
        Serializer.SaveScreenshot (screenshotTex, fileName);
        Destroy (screenshotTex);
    
        KickStarter.stateHandler.PostScreenshotBackup ();
    
        foreach (Menu menu in PlayerMenus.GetMenus ())
        {
            menu.PostScreenshotBackup ();
        }
    
        isTakingSaveScreenshot = false;
        GatherSaveFiles ();
    }
    

    Then in PlayerMenus, replace the following on line 278:

    if (doResizeMenus > 0)
    

    with:

    if (doResizeMenus > 0 || KickStarter.saveSystem.isTakingSaveScreenshot)
    
  • When I add to Menu.cs it gives 4 errors

    Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs(155,74): error CS0103: The name `RuntimeCanvas' does not exist in the current context

  • Replace the two mentions of RuntimeCanvas with canvas.

  • Thank you Chris for looking into it.
    I have 5 more new errors instead after replacing all RuntimeCanvas to Canvas in menu.cs

    Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs(155,74): error CS0119: Expression denotes a type', where avariable', value' ormethod group' was expected

    Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs(157,66): error CS0120: An object reference is required to access non-static member `UnityEngine.Component.gameObject'

    Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs(160,48): error CS0120: An object reference is required to access non-static member `UnityEngine.Component.gameObject'

    Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs(167,74): error CS0119: Expression denotes a type', where avariable', value' ormethod group' was expected

    Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs(171,48): error CS0120: An object reference is required to access non-static member `UnityEngine.Component.gameObject'

  • "canvas" with a lower-case "c".

  • edited October 2020

    Thank you it all works but I had to put back

    private string GetSaveExtension ()
    {
    if (GetSaveMethod () == SaveMethod.XML)
    {
    return ".savx";
    }
    else if (GetSaveMethod () == SaveMethod.Json)
    {
    return ".savj";
    }
    return ".save";
    }
    to SaveSystem.cs since it was giving me

    Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs(92,149): error CS0103: The name `GetSaveExtension' does not exist in the current context

    and all refered to GetSaveExtension

    I tried to replace GetSaveExtension to TakeScreenshot gives 9 other errros like
    Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs(92,149): error CS1501: No overload for method TakeScreenshot' takes0' arguments

    Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs(106,71): error CS1502: The best overloaded method match for `System.IO.DirectoryInfo.GetFiles(string)' has some invalid arguments

    Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs(106,71): error CS1503: Argument #1' cannot convertobject' expression to type `string'

  • I made no mention of removing GetSaveExtension. Only that the TakeScreenshot function above should replace the existing TakeScreenshot function.

  • edited October 2020

    Thank you Chris, I shouldn't have removed that, my bad.

    However I noticed now I get all menus (inventory, menu, and other in game menus) flick off and on when autosave is executed. It turns them off and makes a screenshot (in the editor and build). There is no smooth nice screen transition between scenes.

    Is there a way to disable it on autosave?

  • Line 984 of SaveSystem reads:

    if (KickStarter.settingsManager.takeSaveScreenshots)
    

    Amend it to the following to prevent taking a screenshot when autosaving:

    if (KickStarter.settingsManager.takeSaveScreenshots && saveID != 0)
    
  • Autosave saves nicely and no menus flicks when I change scenes now, but the autosave screenshot in load/save menu is not updated.

    Sorry to drag this on and take your time Chris.

  • Are you looking to disable save screenshots for the autosave, or show menus during it? It's got to be one or the other, if you don't want to have the menu flickering, which is necessary when saving in order to hide them from the screenshot.

    To allow for save screenshots when autosaving, but show menus during it, undo the previous change and replace the TakeScreenshot coroutine with:

    private IEnumerator TakeScreenshot (string fileName, int saveID)
    {
        if (saveID > 0)
        {
            isTakingSaveScreenshot = true;
            KickStarter.stateHandler.PreScreenshotBackup ();
            foreach (Menu menu in PlayerMenus.GetMenus ())
            {
                menu.PreScreenshotBackup ();
            }
        }
    
        yield return new WaitForEndOfFrame ();
    
        Texture2D screenshotTex = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
    
        screenshotTex.ReadPixels (new Rect (0f, 0f, Screen.width, Screen.height), 0, 0);
        screenshotTex.Apply ();
    
        Serializer.SaveScreenshot (screenshotTex, fileName);
        Destroy (screenshotTex);
    
        KickStarter.stateHandler.PostScreenshotBackup ();
    
        foreach (Menu menu in PlayerMenus.GetMenus ())
        {
            menu.PostScreenshotBackup ();
        }
    
        isTakingSaveScreenshot = false;
        GatherSaveFiles ();
    }
    

    Then replace:

    StartCoroutine ("TakeScreenshot", GetSaveScreenshotName (saveID));
    

    with:

    StartCoroutine (TakeScreenshot (GetSaveScreenshotName (saveID), saveID));
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.