Reading a sub value from a saved Component, without instantiating it?

Discussion and help for Easy Save 3
Post Reply
BoxxyPrime
Posts: 1
Joined: Mon Nov 20, 2023 10:58 pm

Reading a sub value from a saved Component, without instantiating it?

Post by BoxxyPrime »

Hey there. Just getting kind of situated with Easy Save, which has been pretty awesome so far. I'm working on a city builder game, and when saving, I'm saving the buildings, pawns, etc using ES3.Save("thing", Pawn/Building), etc. When loading, I'm using something like

Code: Select all

HarvestableResource resource = ES3.Load<HarvestableResource>($"Resource_{GUIDs[i]}");
which creates a gameObject with the component I've saved. That's fine, and I can pull the sub entry from that (A GUID that points to a ScriptableObject that holds a reference to the prefab I want to instantiate), but I'm curious if I could read a sub entry in the save file without actually using Load if that makes sense. It'd also be useful because my Buildings, Pawns, etc, have a Start function that generates things if they're first being placed. Something like

Code: Select all

ES3.FindEntry("Building_GUID").SubEntry
to just read the value - in my case an identifier that points to a ScriptableObject that holds the data for that particular object.

I have tried just maintaining the reference to the ScriptableObject, but for some reason when I load it keeps showing up as null. I don't have the original code for that, at this point but I may accidently swing back around to that haha.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Reading a sub value from a saved Component, without instantiating it?

Post by Joel »

Hi there,

It's not possible in the way you've described unfortunately as random-access happens at a key level, not a field level. The alternative would be to save the variable as a separate key.

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