Loading scriptable objects that contain sprites

Discussion and help for Easy Save 3
Post Reply
georgetas123
Posts: 2
Joined: Wed Oct 28, 2020 1:03 pm

Loading scriptable objects that contain sprites

Post by georgetas123 »

So I am able to save my game but not able to load it. For some reason, I don't know why, when the game loads the sprites are lost. If anyone can give me a hand with this I would be grateful!
Screenshot 2020-10-28 150506.png
Screenshot 2020-10-28 150506.png (16.55 KiB) Viewed 966 times
Screenshot 2020-10-28 150405.png
Screenshot 2020-10-28 150405.png (10.9 KiB) Viewed 966 times
When I have no saved file in the beginning everything works fine it also says that my game was saved and everything. After I save the game and quit play mode and enter play mode again, the game loads, but this image appears so the sprites are completely gone from the game and from the scriptable object instance.
Screenshot 2020-10-28 150526.png
Screenshot 2020-10-28 150526.png (10.68 KiB) Viewed 966 times


public void SaveItems()
{
ES3.Save("Items", ItemList);

foreach (var itemScriptableObject in ItemList)
{
ES3.Save("Sprite", itemScriptableObject.GetSprite());
}
Debug.Log("Items Saved");
}

public void LoadItems()
{
ItemList = ES3.Load("Items", ItemList);

foreach (var tempItem in ItemList)
{

tempItem.itemSprite = ES3.Load("Sprite", tempItem.GetSprite());
if (!CanAddItem()) return;
GetEmptyInventorySlot().SetItem(tempItem);
}

Debug.Log("Items Loaded");

OnItemListChanged?.Invoke(this, EventArgs.Empty);
}

This is the way I save and load I have no clue if it ok to save the sprite like that probably that's why is not working
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Loading scriptable objects that contain sprites

Post by Joel »

Hi there,

I can see an error in your code:

This code will overwrite the same Sprite as you're using the same key each time. Instead you would need to save an array of Sprites.

Code: Select all

foreach (var itemScriptableObject in ItemList)
{
ES3.Save("Sprite", itemScriptableObject.GetSprite());
}
You should also check that there is a reference to your Sprite in the reference manager by right-clicking it in the Assets folder and selecting Easy Save 3 > Add Reference to Manager.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
georgetas123
Posts: 2
Joined: Wed Oct 28, 2020 1:03 pm

Re: Loading scriptable objects that contain sprites

Post by georgetas123 »

That worked i just had to assing the references to the scriptable objects.
Thank you very ,much
Post Reply