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!
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.
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
Loading scriptable objects that contain sprites
-
- Posts: 2
- Joined: Wed Oct 28, 2020 1:03 pm
Re: Loading scriptable objects that contain sprites
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.
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
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());
}
All the best,
Joel
-
- Posts: 2
- Joined: Wed Oct 28, 2020 1:03 pm
Re: Loading scriptable objects that contain sprites
That worked i just had to assing the references to the scriptable objects.
Thank you very ,much
Thank you very ,much