I have a in-scene game object(Manager) that is assigned a script. Within this script it has an assigned ScriptableObject asset. During play mode I can swap out this assigned ScriptableObject through a shop. I have an Awake() and OnApplicationQuit() method that saves the ScriptableObjects to a list. But when I restart the scene or game my Manager does not save what ScriptableObject it had assigned to it and instead reverts back to default. I will provide pictures below.
What I want to know basically, is there a way to save assigned ScriptableObjects to an in-scene script and have that script save which ScriptableObject it had assigned to it on restart.
Saving Assigned ScriptableObjects to an in-scene object on quit
Re: Saving Assigned ScriptableObjects to an in-scene object on quit
Hi there,
Are you getting any warnings in the console when you load?
All the best,
Joel
Are you getting any warnings in the console when you load?
All the best,
Joel
Re: Saving Assigned ScriptableObjects to an in-scene object on quit
Nope, no warnings, and I also have an easy save manager with references all set up. My scriptable objects themselves are saving, the object is just not saving what scriptable object it had assigned to it.
Re: Saving Assigned ScriptableObjects to an in-scene object on quit
Hi there,
If Easy Save fails to load a reference then it will output a warning to the console, so it would indicate that the field in question isn't being saved. Please could you show me where you declare the field which isn't being loaded. You should also check that it is a field which will be automatically serialized at runtime (see https://docs.moodkie.com/easy-save-3/es ... ted-types/)
All the best,
Joel
If Easy Save fails to load a reference then it will output a warning to the console, so it would indicate that the field in question isn't being saved. Please could you show me where you declare the field which isn't being loaded. You should also check that it is a field which will be automatically serialized at runtime (see https://docs.moodkie.com/easy-save-3/es ... ted-types/)
All the best,
Joel
Re: Saving Assigned ScriptableObjects to an in-scene object on quit
Here is the code for my pipe spawner where I declare the assignedPipe ScriptableObject
Thanks for your help!
Ive tried looping through my ownedPipes List on Awake() and assigning the pipe that has the bool "isEquipped" to my assigned pipe. This works if only one pipe is assigned to something. I am trying to make this work so I can have multiple "PipeSpawners" that have ScriptableObjects attached to their scripts that save on quit and load properly.Thanks for your help!
Re: Saving Assigned ScriptableObjects to an in-scene object on quit
Hey there, most of my replies are not very helpful but I still try!
I do use save to cache then on quit save that cache file.
I use scriptables for my inventory items, and had an issue of them not loading into the inventory.
My solution was to create a reference to the scriptable object and save that list.
In this case, my inventory. I have items inheriting from inventoryitem, like ammo, weapoons, recordings etc... and use this way to save and load them.
Below playerinventory is the on character inventory that changes as you play. So when you hit save it then does the for loops to check each slot and save what is there.
So like this:
[Tooltip("Use Inventory Scriptable from Assets")] [SerializeField] private PlayerInventory playerInventory;
Then in save for each type of inventory item:
for (int i = 0; i < playerInventory._weapons.Count; i++)
{
ES3.Save("Weapons", playerInventory._weapons);
}
for (int i = 0; i < playerInventory._ammo.Count; i++)
{
ES3.Save("Ammo", playerInventory._ammo);
}
Etc....
I also have shared floats where I change the value of scriptable object, that one threw me off. But I create a lisdt of them and save the list (the list gets reset on start, I use a default value and change the runtime value only)
[Tooltip("Scriptable Objects Shared Float (Health etc...")]
[SerializeField] private List<SharedFloat> scriptables;
ES3.Save("Scriptables", scriptables);
Now for this one,I use Loadinto:
if (ES3.KeyExists("Scriptables")) ES3.LoadInto("Scriptables", scriptables);
I hope this helps with some ideas to try.
I do use save to cache then on quit save that cache file.
I use scriptables for my inventory items, and had an issue of them not loading into the inventory.
My solution was to create a reference to the scriptable object and save that list.
In this case, my inventory. I have items inheriting from inventoryitem, like ammo, weapoons, recordings etc... and use this way to save and load them.
Below playerinventory is the on character inventory that changes as you play. So when you hit save it then does the for loops to check each slot and save what is there.
So like this:
[Tooltip("Use Inventory Scriptable from Assets")] [SerializeField] private PlayerInventory playerInventory;
Then in save for each type of inventory item:
for (int i = 0; i < playerInventory._weapons.Count; i++)
{
ES3.Save("Weapons", playerInventory._weapons);
}
for (int i = 0; i < playerInventory._ammo.Count; i++)
{
ES3.Save("Ammo", playerInventory._ammo);
}
Etc....
I also have shared floats where I change the value of scriptable object, that one threw me off. But I create a lisdt of them and save the list (the list gets reset on start, I use a default value and change the runtime value only)
[Tooltip("Scriptable Objects Shared Float (Health etc...")]
[SerializeField] private List<SharedFloat> scriptables;
ES3.Save("Scriptables", scriptables);
Now for this one,I use Loadinto:
if (ES3.KeyExists("Scriptables")) ES3.LoadInto("Scriptables", scriptables);
I hope this helps with some ideas to try.
Re: Saving Assigned ScriptableObjects to an in-scene object on quit
I will try this and get back to here.
Thanks for the suggestion!
Edit: For now I will just stick with looping through my ownedPipes on start and finding the one that is currently equipped and assigning that one. It is working for now but I still would like to figure out how to avoid doing this in the future.
Once again thanks for the help!
Thanks for the suggestion!
Edit: For now I will just stick with looping through my ownedPipes on start and finding the one that is currently equipped and assigning that one. It is working for now but I still would like to figure out how to avoid doing this in the future.
Once again thanks for the help!
Re: Saving Assigned ScriptableObjects to an in-scene object on quit
BTW--Have you checked the save file to see if it is even saving all the values first? So the issue is in the load or the save.
I forgot to mention when I load back that inventory,. I do not for loop through, I just load the value.
This is just a nitpick but you have 3 getcomponents called in a short statement and looping through that as well.
Just to be more efficient, try putting the load portion into a separate method and cache the reference to getcomponent.
Can you possibly just save the ones that are true? That way you just load values and don't have to loop through anything.
Or mark them true and save the entire thing and let the save just load both false and true as it should be. It might be only loading the first one since you loop through the save looking only for the true ones, but no harm in loading the false ones too. Try that, remove the for loop and just load the value of the save. So, loop through and save all pipes. then load just the "pipes" value.
So
PlayerScript playerScript;
void Start()
playerScript = getcomponent (etc...)
AssignPipes();
void AssignPipes()
if(playerScript != null)
{
assignedPipe = es3load("pipes", assignedpipes) //or something like thiis
}
I forgot to mention when I load back that inventory,. I do not for loop through, I just load the value.
Code: Select all
if (ES3.KeyExists("Weapons")) playerInventory._weapons = ES3.Load("Weapons", playerInventory._weapons);
Code: Select all
if (ES3.KeyExists("Ammo")) playerInventory.Ammo = ES3.Load("Ammo", playerInventory._ammo);
Just to be more efficient, try putting the load portion into a separate method and cache the reference to getcomponent.
Can you possibly just save the ones that are true? That way you just load values and don't have to loop through anything.
Or mark them true and save the entire thing and let the save just load both false and true as it should be. It might be only loading the first one since you loop through the save looking only for the true ones, but no harm in loading the false ones too. Try that, remove the for loop and just load the value of the save. So, loop through and save all pipes. then load just the "pipes" value.
So
PlayerScript playerScript;
void Start()
playerScript = getcomponent (etc...)
AssignPipes();
void AssignPipes()
if(playerScript != null)
{
assignedPipe = es3load("pipes", assignedpipes) //or something like thiis
}