Loading a List loose reference of prefabs loaded at runtime

Discussion and help for Easy Save 3
Post Reply
Drannach
Posts: 2
Joined: Sat Jan 07, 2023 11:22 am

Loading a List loose reference of prefabs loaded at runtime

Post by Drannach »

Hello!
I've got a problem that it seems i cannot solve alone...
My player has a List that that hold the inventory, the object inside it are simple c# classes (eg. weapons).
Inside those classes i have another List which are weapon mods(c# classes too).
Inside those weapon mods i can have as an example a scope model to load at runtime held in a public GameObject variable.

When i save the inventory using (items is the List) :

Code: Select all

ES3.Save("MainInventory", items);
I get a reference to the prefab that holds the scope model (this is part of the save file)

Code: Select all

"scopeModelGO" : {
		"_ES3Ref" : "3925392695620607158"
},
but when i try to load it back after restarting the game using

Code: Select all

items = ES3.Load<List<IInventoryItem>>("MainInventory");
the reference is lost and the scope cannot be loaded.
The same for the projectile prefab(and this is stored on the weapon class, not is the mods).
The weapons are there with all the variables backed up, except for the references to the prefabs
I've done the " Right click the prefab and select Easy Save 3 -> Enable Easy Save for Prefabs" for every single scope and projectile prefab, and those are in the Easy Save 3 Manager under ES3Prefabs.
I also checked every field under the classes in the Type tab of easy Save 3 window, infact they seem to be serialized properly. i think it's just a loading problem
I'm sure i'm missing something important but i cannot seem to find out what it is...
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Loading a List loose reference of prefabs loaded at runtime

Post by Joel »

Hi there,

Firstly, while the scene which you're loading is open, try right-clicking the prefabs and selecting Easy Save 3 - Add References to Manager, and then deleting your save data using Tools - Clear persistent data path. This ensures that the prefabs are a dependency of your scene.

If this doesn't resolve your issue please could you create a new project with a simple scene which replicates this and private message it to me with instructions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Drannach
Posts: 2
Joined: Sat Jan 07, 2023 11:22 am

Re: Loading a List loose reference of prefabs loaded at runtime

Post by Drannach »

Holy crap it works wonerfully... I think i tryed everything except this...
Thanks a lot for the help Joel!
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Loading a List loose reference of prefabs loaded at runtime

Post by Joel »

Glad to hear it, let me know if you run into any other issues :)

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply