Page 1 of 1

Difficulty loading images opened from an iPhone camera roll? A problem with references I guess.

Posted: Sun Sep 12, 2021 10:59 pm
by jcal
Currently saving and loading a dictionary that keeps track of a struct containing a string Name, float Rating, and sprite Image. The images are uploaded from a users iPhone camera roll into the project during runtime, so they are created dynamically. From my understanding of the errors this has generated, it only really saves a reference to those images, not the sprite data itself. This causes a problem upon loading where no image loads and I get a warning from ES3 saying "Reference for UnityEngine.Texture2D with ID 9219524267810234602 could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored." (I tried changing the type from sprite to Texture2D throughout the script to see if it handled a texture better) Is there something different I should be doing?

I did have success in trying to recreate the procedure in a standalone project that was simply just opening a photo from the camera roll and saving it then loading it on start, I received the same error but it appeared that the image still loaded. However the biggest difference I can find between the projects is in my actual project (the original one discussed) saves and loads a dictionary of structs that contain a texture2D. On the other hand, the project that was successful was purely loading a single texture2D file.

Is this a problem with trying to load references that have 'expired'? Or is it a problem with the the way my data is structured that I'm saving, like is a dictionary of structs not the best way to handle saving and loading dynamic data?

Re: Difficulty loading images opened from an iPhone camera roll? A problem with references I guess.

Posted: Mon Sep 13, 2021 7:37 am
by Joel
Hi there,

This will occur because you're saving the Texture by reference, but a reference to that Texture will no longer exist after you leave the scene.

Instead you should save and load it directly (i.e. ES3.Save<Texture2D>("yourKey", yourTexture)) before loading your Dictionary to ensure that it is stored by value.

All the best,
Joel

Re: Difficulty loading images opened from an iPhone camera roll? A problem with references I guess.

Posted: Mon Sep 13, 2021 7:37 am
by Joel
Hi there,

This will occur because you're saving the Texture by reference, but a reference to that Texture will no longer exist after you leave the scene.

Instead you should save and load it directly (i.e. ES3.Save<Texture2D>("yourKey", yourTexture)) before loading your Dictionary to ensure that it is stored by value.

All the best,
Joel

Re: Difficulty loading images opened from an iPhone camera roll? A problem with references I guess.

Posted: Mon Sep 13, 2021 9:30 pm
by jcal
Joel wrote: Mon Sep 13, 2021 7:37 am Hi there,

This will occur because you're saving the Texture by reference, but a reference to that Texture will no longer exist after you leave the scene.

Instead you should save and load it directly (i.e. ES3.Save<Texture2D>("yourKey", yourTexture)) before loading your Dictionary to ensure that it is stored by value.

All the best,
Joel
I'm about to get back to work on the project now and I'll try out your method. I will say that I found success by saving the actual path the image is loaded from as a string and then loading an image from that path using another utility which worked perfectly when testing in unity. But once I exported the project to my phone I was met with... interesting results. They lead me to believe that the path the photos have is just a temporary location for the most recently loaded image, because changing one image would result in all other uploaded images to become the same image, probably because they're all from the same path.

If I understand what your saying, this is a problem with the way I've structured my data. Because I'm saving a dictionary of structs containing the texture or sprite I'm not really doing myself any favors. I'll try your solution now and restructure the way images are saved and loaded.

Side note, it means a lot that you were able to get back to me on this. I was definitely worried about the price of ES3, but I gotta say, money well spent. It's easy to use and understand, full of features I can see myself using in the future, and the support has been great!

Thank you so much.

Re: Difficulty loading images opened from an iPhone camera roll? A problem with references I guess.

Posted: Tue Sep 14, 2021 7:33 am
by Joel
Glad you're finding Easy Save useful. Let me know how you get on with the solution I suggested when you have a chance to try it :)

All the best,
Joel

Re: Difficulty loading images opened from an iPhone camera roll? A problem with references I guess.

Posted: Fri Sep 17, 2021 2:08 pm
by jcal
Joel wrote: Tue Sep 14, 2021 7:33 am Glad you're finding Easy Save useful. Let me know how you get on with the solution I suggested when you have a chance to try it :)

All the best,
Joel
Yeah after countless pointless attempts and rewritings I got nowhere. The problem was never ES3, it was the way I was loading the texture from the OS and the plugin I used. It was by default setting textures to non readable which required to me to in every case try to access the data from an unreadable texture which would always just be a reference which ES3 did not like. All I had to do was include a "true" in one line and now all incoming textures are readable, encodable to PNG, and I'm saving a byte[] array for each image and loading them. Worked perfectly in a separate project I made just for testing out multiple image saving and loading with ES3, got it to work perfectly in my main project as well.

Thank you for the support! I imagine these forums will be infinitely useful once I attempt to start saving data online.

Thank you again!

Re: Difficulty loading images opened from an iPhone camera roll? A problem with references I guess.

Posted: Sat Sep 18, 2021 7:50 am
by Joel
Glad you managed to resolve your issue :)

All the best,
Joel