Forum rules - please read before posting.

Get the saving screenshot image

Hello !
I am currently building my custom save menu. I was mainly inspired by RetroSavesUI menu available on the Download page, thank you for this asset.
I want to combine this system with the save screenshots: when I click on one element of the list, I want the corresponding screenshot to appear on a dedicated area (UI Image object).
I tried the following script, attached on the Image object but it does not work (as in the RetroSavesUI, the clicked slot is stored in a global variable, here the 12th).

            int slot = AC.GlobalVariables.GetIntegerValue(12);
            Texture2D mynewTxture = AC.SaveSystem.GetSaveSlotScreenshot(slot, slot, true);
              Sprite mySprite = Sprite.Create(mynewTxture, new Rect(0.0f, 0.0f, mynewTxture.width, mynewTxture.height), new Vector2(0.5f, 0.5f), 100.0f);
              this.gameObject.GetComponent<Image>().sprite = mySprite;

Also, I am willing to give custom name to the save slot, but I don't manage to do it throught the actionList. I would like a format like : NameOfTheGame_SaveNumber_Date_Time. Is it possible through actionList or do I need to write custom script ?

Thanks in advance for your precious help !

Comments

  • In what way does the code above not work, and when/how are you running it?

    It's not necessary to convert the Texture2D to a Sprite - if you replace your Image component with a RawImage, you can assign the Texture2D directly.

    If variable 12 refers to the clicked menu slot - not the save ID - you'll want to pass the GetSaveSlotScreenshot's third parameter as false.

    I am willing to give custom name to the save slot, but I don't manage to do it throught the actionList.

    You can set the default save format at the top of the Settings Manager, but it doesn't include the save number - only the game name and date/time.

    The Save: Save or load Action lets you set the name of a save from a Global String variable when saving, but to make it dynamic you'll want to have a custom script that hooks into the OnFinishSaving custom event to update the label:

    using UnityEngine;
    using AC;
    
    public class UpdateSaveLabel : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnFinishSaving += OnFinishSaving; }
        private void OnDisable () { EventManager.OnFinishSaving -= OnFinishSaving; }
    
        private void OnFinishSaving (SaveFile saveFile)
        {
            string dateString = System.DateTime.Now.ToString (KickStarter.settingsManager.customSaveFormat);
            string saveLabel = "MyGameName_" + saveFile.saveID + "_" + dateString;
            KickStarter.saveSystem.RenameSaveByID (saveLabel, saveFile.saveID);
        }
    
    }
    

    Paste that in a new C# script named UpdateSaveLabel and place in your scene. To change the date format, set your Settings Manager's Time display field to Custom Format.

  • Hi Chris,
    Thank you for your usefull tips. I am now able to get the screenshot of the save using the RawImage instead of the Image.
    I am almost there for the custom name. I added your script to my scene name and now a custom name is given to the save. Nevertheless, a weird behaviour is happening. If I select the first slot for the save, the new custom name is given to the second slot (but the save is actually behind the first slot). Do you know where it could come from ?
    Thank you very much in advance !

  • The first slot in your SavesList normally represents the Autosave - is that the case here?

    Is this only when selecting the "first slot", or is the save label affecting always affecting the wrong slot?

    If you can share screenshots showing the issue, that'll help make things more clear.

  • edited April 2021

    Okay so I think multiple problems are causing the issue here : the name is not put in the right place but neither is the actual save.
    When I have no save, all the allocated buttons are labelled "New Save" so I assumed there was no room for Autosave (and I don't want it).
    The Save label and the save itself are always affected to the wrong slot.
    Example : if I click on the fourth slot, the save is behind the first slot and the name is changed on the second slot.

    I checked the Global Integer value of Slot_ID through an Update and the value is correctly updated to the one the user click on.
    My actionList for the Savebutton is Save/Save or Load/Overwriting existing/Slot Index from Value / Save_ID
    The actionList for the SaveList is Variable/Set/Global/Save_ID/Entered Here/Set Value/ -> Statement: = 0:Save ID

  • In the case of your example of clicking the fourth slot, what is the variable set to, and what does the Console report when saving?

    The above script works for me when using it in conjunction with the Retro Saves UI - if you're using a separate menu, it may be some key difference in the way your menu/element is configured.

    Try temporarily switching to the Retro Saves UI - does the script rename the save for you then?

  • Hello Chris,
    So sorry for the late reply, I made a pause in the game development.
    It is not working either with the Retro Saves UI. I guess I have something else in the game which is conflicting with the menu. I'll try to investigate it. If I don't manage to solve it I will just go with a simpler Save and Load process.

  • Hello!
    I want to achieve a similar effect and I need some recomendation here, with your experience. I have a very nice save and load menu made with AC. The thing is that we want to create a list of saves, and on hover, show the screenshot.

    1) No way (even with a scipt) to do it with AC solely right?

    2) I've used the Retro UI you did and it works lovely. The only thing I need is how can I (using the same labels, index from your Readme file) show the screenshot.
    I'm not so sure if the scripts provided here work on 1.75.3 and/or can be used using the logic of the Retro UI. I'm putting Retro UI because it will be easier for any other user to compare against it.
    Thanks!

  • I forgot two things:
    3) The AC savegame doesn't allow "New save" to be translated to other languages right?
    4) Instead of inputting something on click, I want to automatically add a certain name such as "Save 01" + Timestamp. Is there a way to do add that instead of inputting something? Or even the default things the AC save system adds when you use AC source.

    Thanks!

  • No way (even with a scipt) to do it with AC solely right?

    AC's GetSaveSlotScreenshot function can be called to retrieve the screenshot for a given save game - this can be incorporated into an OnMouseOverMenu event hook to update the texture of a RawImage component:

    private void OnEnable() { EventManager.OnMouseOverMenu += OnMouseOverMenu; }
    private void OnDisable() { EventManager.OnMouseOverMenu -= OnMouseOverMenu; }
    
    private void OnMouseOverMenu (Menu menu, MenuElement element, int slot)
    {
        if (element is MenuSavesList)
        {
            Texture2D saveScreenshot = AC.SaveSystem.GetSaveSlotScreenshot (slot, slot, false);
            rawImage.texture = saveScreenshot;
        }
    }
    

    The AC savegame doesn't allow "New save" to be translated to other languages right?

    It does. "New save" text is a property of the SaveList element, and will appear in the Speech Manager as the text type "Menu Element".

    Instead of inputting something on click, I want to automatically add a certain name such as "Save 01" + Timestamp.

    The Save: Save or load Action can be used to save a game with a custom label - but this doesn't have to be linked to an Input element. You could have the label refer to a Global String Variable, and update that variable before saving.

  • Very helpful! I honestly didn't want to change the save/load system already implemented with a custom menu or gameobjects flying around the screen. So, for anyone wondering how to do what was asked here.
    1) Did the Save and Load menus, only showing the label (not the screenshot). Also didn't apply any background image.
    2) Created a Canvas object. Child: Background image (a semi transparent screen). Another child: the frame of the screenshot (also an image). Inside this object, the Screenshot object as Raw Image. By default, the Alpha of the picture is 0. This is because if you don't have a save, then an empty white screen will be displayed and doesn't look good.
    3) The script attached to the Screenshot object:

    using UnityEngine;
    using AC;
    using UnityEngine.UI;

    public class SaveLoadScreenshot : MonoBehaviour
    {
    public RawImage rawImage;

    public void Start()
    {
        rawImage = GetComponent<RawImage>();
    }
    public void OnEnable() { EventManager.OnMouseOverMenu += OnMouseOverMenu; }
    public void OnDisable() { EventManager.OnMouseOverMenu -= OnMouseOverMenu; }
    
    public void OnMouseOverMenu(Menu menu, MenuElement element, int slot)
    {
        if (element is MenuSavesList)
        {
            Texture2D saveScreenshot = AC.SaveSystem.GetSaveSlotScreenshot(slot, slot, false);
            if (saveScreenshot != null)
            {
                rawImage.color = new Color32(255, 255, 255, 255);
                rawImage.texture = saveScreenshot;
            }
            else
            {
                rawImage.color = new Color32(0, 0, 0, 0);
            }
    
        }
    }
    

    }

    4) Prefabs the whole many, deleted the object, and created an action list called Save Load Turn on and added this AL to the Load and Save Menu.
    5) The whole point of the AL is to "Object-Add Remove" the prefab.
    That's it! Simple and nice
    6) The Alpha is handled as two lines in the script: when there's something, it will restore the 255 values. If not, then no values at all.

    Thanks a lot for everything. I have more things to add to the wiki :)

  • Hello! I honestly don't remember having this issue but apparently I am.
    The problem is simple: the menus are halfway hiding before taking the screenshot so I'm getting black screens (the color of the background of my canvas).

    How it's set up: The Save/Load are AC but I also load on top of it when turning it on, an Object (canvas, panel, etc.). This is the first screenshot.

    Second screenshot: gameplay.

    Third screenshot: pause menu (as you can see, there's a background with a heavy alpha on top; it's not plain black). This is a prefab which is called on ESC or by clicking on the clip. Two different AL to do the same thing.

    Fourth screenshot: I have the Pause, and there the Save and Load. This is done by another prefab which is called uppon clicking.

    Fifth: I saved, that's the screenshot. No other menu is interferring.

    I've noticed AC correctly hides the AC part of the menu but not the object (the background and the panel I created for it) so I was wondering if there's a way to hide this as well so that the screenshot is actual gameplay and not anything related to menus.

    If it's impossible then I think I may have to create another custom menu using Unity Interface (just want to make sure before creating another one). I briefly tested this before writing and didn't work as well so maybe I might be having something wrong and the background is not hiding correctly.

    The other question is that I noticed that "clickable in cutscenes" apparently doesn't mean what I believe: I can't save during cutscenes, right? I get always an error and doesn't save. I guess I may need to find out it via script if it's cutscene or not, so I can disable the button?

    Thank you very much. Honestly, didn't remember having this problem but, I guess I do.

  • AC correctly hides the AC part of the menu but not the object (the background and the panel I created for it

    AC will disable the scene instance of the linked Canvas prefab assigned in the Menu's properties, which should be on the prefab's root. Where is the background/panel in your Hierarchy?

    If you wanted to control the visibility of a separate object while saving, you could do this by hooking into the OnBeforeSaving and OnFinishSaving custom events.

    I noticed that "clickable in cutscenes" apparently doesn't mean what I believe: I can't save during cutscenes, right?

    The "Clickable in cutscenes" option refers to the game-state at the time the Menu is clicked. In this case, this will be Paused because your Menu is set to Pause the game when enabled.

    Saving isn't possible when gameplay-blocking ActionLists are running - i.e. the game-state is Cutscene, or will be if no Menus that pause the game are enabled.

    To determine if the game can currently be saved, and therefore if your "Save" button element should be visible, you can use the Save: Check Action inside the Menu's ActionList when turn on asset.

  • I made it work. Not sure why yesterday was not working. I had to re-create the whole menu again using Unity UI.
    About the Save: Check I put a logic in which if it's cutscene, then the Save label is different (Cutscene: can't save now). Using show/hide elements I made it work. Thanks for that.
    I followed the custom saves tutorial and I have to re-read it many more times. The parameters vs. variables in my head is a mess to me.

    There is only one thing I can't make it work which is the Delete part of the saves. I've created another screen in which I should bring the saves and then upon clicking, delete them individually. How can I retrieve that list? I've noticed the "List type: Import" but not sure what goes in those parameters. Haven't found forum or manual reference to it. If it's even possible of course.

    Thanks a lot!

  • Use a List type of Load - that'll display existing save files that the user can then choose from to delete.

    Uncheck Load when click on?, and then assign an ActionList with an integer parameter that can be mapped to the clicked slot index.

    "Import" refers to the importing of variable from another game's save files - in the case that you're making an episodic game like The Walking Dea series, where you want to transfer information about the users progress from previous episodes.

  • Thank you very much. Everything worked and the menu looks better now :)

    I have noticed few things (pics below)

    https://imgur.com/a/ZjP9VcF

    1) I don't know why but I have a problem with the screenshots when saving to random slots. As you can see, I saved on the last slot, but it doesn't have a screenshot. It has it in slot 3. I guess the screenshots are saved "in order" and not using the global variable. I think here are the mistakes.
    public void OnMouseOverMenu(Menu menu, MenuElement element, int slot)
    {
    if (element is MenuSavesList)
    {
    Texture2D saveScreenshot = AC.SaveSystem.GetSaveSlotScreenshot(slot, slot, false);

    Those "slots" probably should relate to global variable number 24 which is our Global Variable. I think I'm close but not sure how to combine both...

    2) There's another thing that is driving me crazy. The slots have a SFX when hover. We also put a little box that says "Game Saved!" when saved. 50% of what I wanted is done: the color change on hover is affected by this new panel on top: great. But the hover continues on an on. I found that a little workaround is Engine: Menu, disable. That makes the SFX dissapear but at the same time, it doesn't show the update on the button: it doesn't show the date, save 1, 2, etc. It doesn't look nice to show that it saves when you can see nothing behind.

    I tried all kind of raycast blockings, even lowering the SFX volume to zero (it takes like a second to do so not so good option). Tried visibility stuff but no luck since the Texts are children of the boxes (I guess that's how AC can write the date and number of save)

    I'm thinking a script which kills the sound and then re-enables it. Or at least kill that hover SFX related to that particular menu. Or any other idea you can think of to block that interaction. Just the sound. The color part is taken care already by a transparent image.

    Thanks for everything as always :)

  • Those "slots" probably should relate to global variable number 24 which is our Global Variable.

    You Save element maps the "Save slot index" parameter to the clicked slot ID - not the index. See the "(= Save ID#)" label beside it.

    But the hover continues on an on.

    I'll need more details about when this occurs exactly. Is it only after saving while the "Game saved" menu shows? Is it when moving the mouse on/off a save slot / when hovering on/off another menu?

  • Hello Chris,

    The naming of the parameter was the same as the Varible, true, but the linking was alright (in fact, I don't have more options to choose from).

    The system works fine! The problem was solely on the screenshot.
    This was where the error comes from:

    Texture2D saveScreenshot = AC.SaveSystem.GetSaveSlotScreenshot(slot, slot, true);

    I had to modify the "false" to "true". That fixes the error completely and the screenshots saves correctly. Problem 1 completely solved!

    -

    As for the Sound part, the problem is that the hovering sfx continue working even when another panel on top is in place. This pannel is supposed to "kill" the hovering from when you enter the pointer to the buttons. To put it simple: when I want to save on a slot, the hovering should be working (it works). When you are done saving, a new panel is placed on top (the one that says Game Saved! in the pictures). What I need is to not allow the hovering SFX over the buttons to continue working. My question is how can I "kill" this hovering sound on this particular part. I tried many methods but none worked :(

    https://imgur.com/a/UxLgnty

    Thanks for everything :)

  • When the "Game Saved!" panel appears, try calling:

    PlayerMenus.GetElementWithName ("Save", "SavesList").isClickable = false;
    

    (Replacing the strings with the names of your Save menu / SavesList element respectively).

    If it works, you'll then need to run the line again, setting it to true, when the panel disappears.

  • Super worked! Thanks a lot for everything :)

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.