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 :)

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.