Hello!
I am currently trying to save and load images using Easy Save 3's SaveImage/LoadImage. It seems to work as expected except when I'm trying to loop through GameObjects and load images using either a for loop or a coroutine. For some reason, all the GameObjects render the last image I was trying to load (screenshot attached). Not sure why that is. When I try to space them out using a coroutine/waitforseconds the images fail to render at all.
This is the code I'm using (condensed to the relevant parts)
for (int i = 0; i < PhotosData.AllPhotos[i].Count; i++)
{
GameObject CurrentItemGameObject = PhotosGameObjects[i];
//This file path is unique to each photo, I double checked this already
string CurrentPhotoName = PhotosData.AllPhotos[i].PhotoFilePath;
Texture2D Texture = ES3.LoadImage(CurrentPhotoName);
Texture.filterMode = FilterMode.Point;
Texture.wrapMode = TextureWrapMode.Clamp;
CurrentItemGameObject.transform.Find("PhotoImage").GetComponent<Image>().material.mainTexture = Texture;
CurrentItemGameObject.transform.Find("PhotoImage").gameObject.SetActive(true);
}
Should I not be looping through and trying to load images? Is there some latency I need to account for? I have tried various solutions without success.
Attachments
Screenshot 2023-12-28 125216.png (74.42 KiB) Viewed 940 times
This issue will be your logic rather than at our end. You should check that CurrentPhotoName isn't referring to the same image, and that the images you're trying to load aren't all the same image when saved. You should also check that CurrentItemGameObject.transform.Find("PhotoImage").GetComponent<Image>().material isn't referring to the same Material for each of your objects. Otherwise changing the Material on one object will change the Material on all objects. However, I recommend asking on the Unity forums for more information as this isn't related to saving and loading.
I did double check that `CurrentPhotoName` was a unique file path hence my comment above that line of code
It was related to the UI image components sharing the same material by default. I was able to fix it like this in case anyone else runs into this problem: