I am trying to have an enlarged screenshot of a clicked save/load slot in a separate menu where you confirm "Do you really want to Load/overwrite this game?"
I tried to recreate the steps described here by Kakyouin (last post from May 2022). However, it is not working for me. I created my own Unity UI menu, and amended the script by Kakyouin (because I want the image to be shown regardless of mouse-over or not, but I assume I broke it with my edit anyway :-D ). But even with the original version, I am getting a white rectangle where the screenshot should be. The Console does not say anything.
The custom Unity UI menu Hierarchy:
Where the ScreenShot has this script attached to it:
using UnityEngine;
using AC;
using UnityEngine.UI;
public class SaveLoadScreenshot: MonoBehaviour
{
public RawImage rawImage;
public void Start()
{
rawImage = GetComponent<RawImage>();
}
public void OnMouseOverMenu(Menu menu, MenuElement element, int slot)
{
if (element is MenuSavesList)
{
Texture2D saveScreenshot = AC.SaveSystem.GetSaveSlotScreenshot(slot, slot, true);
if (saveScreenshot != null)
{
rawImage.color = new Color32(255, 255, 255, 255);
rawImage.texture = saveScreenshot;
}
else
{
rawImage.color = new Color32(0, 0, 0, 0);
}
}
}
}
But maybe there is an easier way? I was thinking since I am using parameters and global variables in this "confirmation/overwrite menu" (discussed here) I could add a SavesList element and make it change its value/ID based ion the specific slot that was previously clicked. But I cannot figure out how to do this, there seems to be option for either a fixed ID or automatic which makes it always the 1st.
OnMouseOverMenu is a custom event, so it needs to be hooked into inside OnEnable (see this tutorial). However, if the screenshot should appear when the menu opens, you should just be able to call it all in Start, i.e.:
using UnityEngine;
using UnityEngine.UI;
using AC;
public class SaveLoadScreenshot: MonoBehaviour
{
public RawImage rawImage;
public void Start()
{
rawImage = GetComponent<RawImage>();
int saveID = GlobalVariables.GetVariable ("Save ID").IntegerValue;
Texture2D saveScreenshot = AC.SaveSystem.GetSaveSlotScreenshot(0, saveID, true);
if (saveScreenshot != null)
{
rawImage.color = new Color32(255, 255, 255, 255);
rawImage.texture = saveScreenshot;
}
else
{
rawImage.color = new Color32(0, 0, 0, 0);
}
}
}
The script works, but i am having trouble with the variable.
If i leave the Save ID, i get an error Object reference not set to an instance of an object on line 11. However, I am using parameter for it called Slot Index, but if I put that instead, I get the same error message.
The only time this works is when I use my global variable name Save slot ID. But in that case, the screenshot that loads is always only the one from the slot I click first. Any other clicked slot has either identical image (although it should not) or it is a white rectangle again.
I am using my global variable Save slot ID, the screenshot shows correctly only the first time (different ones depending on the save), but any other screenshot is then the same as the first one that loaded. The Variable is changing correctly and it is set in advance of the menu with the screenshot showing up (on the image called RealySave). Am I overlooking something?
This sets the variable before the menu with a screenshot opens (we were discussing it in a previous topic about confirming overwrite - it works prefectly for saving into slots)
Temporarily set your SavesList element's Display type to Label Only, and disable the screenshots feature at the top of the Settings Manager - that should remove the unwanted instances of that message.
The same thing shows up once, with the Save number varying depending on the slot I just clicked. Then nothing more.
Get screenshot. Element: 0, Save: 1, Use saveID? True
UnityEngine.Debug:Log (object)
The console writes this info when I freshly run the game and click a slot with a save for the first time. If I then cancel the Load confirmation and instead click a different slot with a save, the exact same screenshot shows up, even though it should be a different one, and the console does not write anything anymore.
If I turn off the whole menu, return to the game, and run the menu again, then no matter what I click, the place for a screenshot is empty (white screen), and the console is still quiet. The same behavior is also when I load a game. No console info.
The change to OnEnable worked, now everything works smoothly! Thank you!
It is attached in the prefab of the menu, in the object that also has a raw image as a component (this object is a child to Panel, which is a child to Canvas).
Comments
I am trying to have an enlarged screenshot of a clicked save/load slot in a separate menu where you confirm "Do you really want to Load/overwrite this game?"
I tried to recreate the steps described here by Kakyouin (last post from May 2022). However, it is not working for me. I created my own Unity UI menu, and amended the script by Kakyouin (because I want the image to be shown regardless of mouse-over or not, but I assume I broke it with my edit anyway :-D ). But even with the original version, I am getting a white rectangle where the screenshot should be. The Console does not say anything.
The custom Unity UI menu Hierarchy:

Where the ScreenShot has this script attached to it:
But maybe there is an easier way? I was thinking since I am using parameters and global variables in this "confirmation/overwrite menu" (discussed here) I could add a SavesList element and make it change its value/ID based ion the specific slot that was previously clicked. But I cannot figure out how to do this, there seems to be option for either a fixed ID or automatic which makes it always the 1st.
If you know the ID of the save to display, you can pass that into the GetSaveSlotScreenshot function's second parameter (and
true
for the third).If you store this ID in an Integer variable, you can extract it with:
OnMouseOverMenu is a custom event, so it needs to be hooked into inside OnEnable (see this tutorial). However, if the screenshot should appear when the menu opens, you should just be able to call it all in Start, i.e.:
The script works, but i am having trouble with the variable.
If i leave the Save ID, i get an error Object reference not set to an instance of an object on line 11. However, I am using parameter for it called Slot Index, but if I put that instead, I get the same error message.
The only time this works is when I use my global variable name Save slot ID. But in that case, the screenshot that loads is always only the one from the slot I click first. Any other clicked slot has either identical image (although it should not) or it is a white rectangle again.
Rename the script's "Save ID" mention to the name of whichever variable you want it to reference.
Then make sure that this variable's value is set to the correct value (using e.g. Variable: Set) before the Menu gets shown.
I am using my global variable Save slot ID, the screenshot shows correctly only the first time (different ones depending on the save), but any other screenshot is then the same as the first one that loaded. The Variable is changing correctly and it is set in advance of the menu with the screenshot showing up (on the image called RealySave). Am I overlooking something?
This sets the variable before the menu with a screenshot opens (we were discussing it in a previous topic about confirming overwrite - it works prefectly for saving into slots)

If the Slot Index variable is set to the save ID, the screenshot should be getting the right one.
Let's see what's going on: open up AC's SaveSystem script and find the function
GetScreenshot
around line 1499.At the top of it, copy/paste:
What shows in the Console?
I am getting a constant flow of 999+ messages the moment i open the Save menu (not the Overwrite confirmation one with the screenshot):
Get screenshot. Element: 0, Save: 1, Use saveID? True
UnityEngine.Debug:Log (object)
The Save number cycles from 1 to 19 (my max number of saves) and this repeats indefinitely.
Temporarily set your SavesList element's Display type to Label Only, and disable the screenshots feature at the top of the Settings Manager - that should remove the unwanted instances of that message.
The same thing shows up once, with the Save number varying depending on the slot I just clicked. Then nothing more.
Get screenshot. Element: 0, Save: 1, Use saveID? True
UnityEngine.Debug:Log (object)
The console writes this info when I freshly run the game and click a slot with a save for the first time. If I then cancel the Load confirmation and instead click a different slot with a save, the exact same screenshot shows up, even though it should be a different one, and the console does not write anything anymore.
If I turn off the whole menu, return to the game, and run the menu again, then no matter what I click, the place for a screenshot is empty (white screen), and the console is still quiet. The same behavior is also when I load a game. No console info.
Where is your SaveLoadScreenshot script attached? Try renaming its Start function to OnEnable.
The change to OnEnable worked, now everything works smoothly! Thank you!
It is attached in the prefab of the menu, in the object that also has a raw image as a component (this object is a child to Panel, which is a child to Canvas).