Scriptable Object variable value is being removed when loading
-
- Posts: 39
- Joined: Thu Apr 01, 2021 4:53 pm
Scriptable Object variable value is being removed when loading
Hello,
I'm not sure if you have seen this before, but when I'm doing a load a variable is being removed. I have a Scriptable Object (item) that is being stored in a Dictionary. Now, one group of items within this Dictionary have one variable that holds another Scriptable Object (like an enum) as a variable. When I load the dictionary, this Scriptable Object (that works as an enum) is being removed from the item Scriptable Object.
This has happened to me before in a smaller project, but I did not pay much attention to it as it was a prototype.
I'm attaching a video with the problem. You can see in the inspector the variable Container Type. It becomes "null" (none) when I load the game.
TIA!
I'm not sure if you have seen this before, but when I'm doing a load a variable is being removed. I have a Scriptable Object (item) that is being stored in a Dictionary. Now, one group of items within this Dictionary have one variable that holds another Scriptable Object (like an enum) as a variable. When I load the dictionary, this Scriptable Object (that works as an enum) is being removed from the item Scriptable Object.
This has happened to me before in a smaller project, but I did not pay much attention to it as it was a prototype.
I'm attaching a video with the problem. You can see in the inspector the variable Container Type. It becomes "null" (none) when I load the game.
TIA!
- Attachments
-
- VideoForMoodkie_Trim (2)_Trim.mp4
- (1.59 MiB) Downloaded 106 times
Re: Scriptable Object variable value is being removed when loading
Hi there,
Are your getting any warnings to console when loading? If not, please could you create a self-contained script(s) which I can drop into a new project which replicates this?
Also just to check, is the ScriptableObject you're storing in a field saved elsewhere? If it's only being saved as a field, it will only be saved by reference.
All the best,
Joel
Are your getting any warnings to console when loading? If not, please could you create a self-contained script(s) which I can drop into a new project which replicates this?
Also just to check, is the ScriptableObject you're storing in a field saved elsewhere? If it's only being saved as a field, it will only be saved by reference.
All the best,
Joel
-
- Posts: 39
- Joined: Thu Apr 01, 2021 4:53 pm
Re: Scriptable Object variable value is being removed when loading
Hello!
- I'm not getting warning when loading
- The Scriptable Object exist in the file system as it's created using the Create/Menu option.
I have been trying to reduce the project to find the reason the bug is happening but it has been challenging, it certainly appears every time I load. If I close and reopen Unity the variables will appear back.
Now, I tried duplicating the project to start doing a bit more drastic testing to find the bug, but I found a different issue (probably because of the duplication?). I'm getting the error message
I just tested saving something as simple as an Integer, and I get that message. I have cleared out the Persistent Path as you have advised in other threads and it does not fix it. When I open the save file using notepad++ it reads:
This is the stack trace:
- I'm not getting warning when loading
- The Scriptable Object exist in the file system as it's created using the Create/Menu option.
I have been trying to reduce the project to find the reason the bug is happening but it has been challenging, it certainly appears every time I load. If I close and reopen Unity the variables will appear back.
Now, I tried duplicating the project to start doing a bit more drastic testing to find the bug, but I found a different issue (probably because of the duplication?). I'm getting the error message
Code: Select all
FormatException: Expected ',' separating properties or '"' before property name, found 'n'.
Code: Select all
null : { null : null, null : null }
Code: Select all
FormatException: Expected ',' separating properties or '"' before property name, found 'n'.
ES3Internal.ES3JSONReader.ReadPropertyName () (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:63)
ES3Reader+ES3ReaderRawEnumerator+<GetEnumerator>d__2.MoveNext () (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:436)
ES3Writer.Merge (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:466)
ES3Writer.Merge () (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:456)
ES3Writer.Save (System.Boolean overwriteKeys) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:482)
ES3Writer.Save () (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:474)
ES3.Save[T] (System.String key, T value, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:103)
ES3.Save[T] (System.String key, T value) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:63)
-
- Posts: 39
- Joined: Thu Apr 01, 2021 4:53 pm
Re: Scriptable Object variable value is being removed when loading
Ah, it seems that it was a problem with the latest update that you already fixed. So you can omit the last message about the FormatException. I'll try to reproduce the other error in a smaller scale
-
- Posts: 39
- Joined: Thu Apr 01, 2021 4:53 pm
Re: Scriptable Object variable value is being removed when loading
Okay, so I did get some Warnings that were hidden in between other warnings that I had. The warning I'm getting is this one:
Now, this seems to be a very picky bug. It happens with certain items yes and not with others. The Scriptable Object is being created on the file system. The file is in a variable of another Scriptable Object, and that Scriptable Object is within a Dictionary. I save and load the dictionary, and when I do that, that variable sometimes gets emptied out.
I was able to reduce my project to bare bones and still have the problem.
Code: Select all
Reference for ContainerType with ID 2082928117821905327 could not be found in Easy Save's reference manager
I was able to reduce my project to bare bones and still have the problem.
Re: Scriptable Object variable value is being removed when loading
Hi there,
This warning occurs because you're trying to load a reference to an object which doesn't exist. For example, it may be that it has not been saved, it has been saved but not loaded yet, or this object was cloned by Unity before it was saved meaning the reference will no longer exist after you leave the scene.
In this circumstance you would need to save it separately, and then load it before attempting to load anything which references it.
All the best,
Joel
This warning occurs because you're trying to load a reference to an object which doesn't exist. For example, it may be that it has not been saved, it has been saved but not loaded yet, or this object was cloned by Unity before it was saved meaning the reference will no longer exist after you leave the scene.
In this circumstance you would need to save it separately, and then load it before attempting to load anything which references it.
All the best,
Joel
-
- Posts: 39
- Joined: Thu Apr 01, 2021 4:53 pm
Re: Scriptable Object variable value is being removed when loading
Hello Joel,
Thanks for the answer!
My assumption was that ES3 would not touch Scriptable Object files that were used (and saved) by reference and only load the reference without touching the file. But it seems that ES3 is reloading the object too even if it's a reference.
Now, why do you think happens intermittently? For example, that Item Scriptable Object has another variable (foo) that is now empty, if I fill it out in the Inspector, the problematic variable (bar) would not be emptied out. The other Items that have this other variable empty (foo) have the problem where the problematic variable (bar) are getting emptied out. Why would the change of this variable (foo) affect the emptying out of another variable (bar) on loading?
Thanks for the answer!
My assumption was that ES3 would not touch Scriptable Object files that were used (and saved) by reference and only load the reference without touching the file. But it seems that ES3 is reloading the object too even if it's a reference.
Now, why do you think happens intermittently? For example, that Item Scriptable Object has another variable (foo) that is now empty, if I fill it out in the Inspector, the problematic variable (bar) would not be emptied out. The other Items that have this other variable empty (foo) have the problem where the problematic variable (bar) are getting emptied out. Why would the change of this variable (foo) affect the emptying out of another variable (bar) on loading?
Re: Scriptable Object variable value is being removed when loading
Hi there,
Just to clarify, Easy Save won't be the cause of new references being created or the reference not existing, this will be external to Easy Save. Easy Save simply looks for the reference with the given ID, and if a reference with the given ID is not found it will throw that warning.
All the best,
Joel
I'm afraid I'm not sure what you mean by this. Please could you explain?My assumption was that ES3 would not touch Scriptable Object files that were used (and saved) by reference and only load the reference without touching the file. But it seems that ES3 is reloading the object too even if it's a reference.
Just to clarify, Easy Save won't be the cause of new references being created or the reference not existing, this will be external to Easy Save. Easy Save simply looks for the reference with the given ID, and if a reference with the given ID is not found it will throw that warning.
All the best,
Joel
-
- Posts: 39
- Joined: Thu Apr 01, 2021 4:53 pm
Re: Scriptable Object variable value is being removed when loading
I attached an image that can explain my assumptions.
- I save and load the Item Database only.
- Let's say we have Item, Item Type, and Category. All three are Scriptable Objects created on the inspector
- Item has a variable for Item Type and Category.
- Item is part of the dictionary
1. When I save and load the Item Database dictionary, I thought ES3 would not touch Item, Item Type, and Categories. I thought it would just load the dictionary info with the references (and not try to "load" Item and Item Type, but I prob don't understand the inner workings of the asset).
2. When I load the Item Database, sometimes the Item Type variable within some Item objects gets emptied out, and I get that warning (but it's not easy to tell why sometimes it does and why sometimes it doesn't).
3. From my testing (and shown in the image), if I add the Category SO to the Item, then on loading, the Item Type does not get emptied out. If Category variable is null in the Item, then Item Type gets emptied out.
- I save and load the Item Database only.
- Let's say we have Item, Item Type, and Category. All three are Scriptable Objects created on the inspector
- Item has a variable for Item Type and Category.
- Item is part of the dictionary
1. When I save and load the Item Database dictionary, I thought ES3 would not touch Item, Item Type, and Categories. I thought it would just load the dictionary info with the references (and not try to "load" Item and Item Type, but I prob don't understand the inner workings of the asset).
2. When I load the Item Database, sometimes the Item Type variable within some Item objects gets emptied out, and I get that warning (but it's not easy to tell why sometimes it does and why sometimes it doesn't).
3. From my testing (and shown in the image), if I add the Category SO to the Item, then on loading, the Item Type does not get emptied out. If Category variable is null in the Item, then Item Type gets emptied out.
- Attachments
-
- ItemProblem - Copy.png (74.03 KiB) Viewed 1640 times
Re: Scriptable Object variable value is being removed when loading
Hi there,
ScriptableObject fields should be serialized by reference. If you're saying that it's being serialized by value, I've not seen this happen before without the member reference mode being manually set to Value or RefAndValue in the settings.
Please could you delete your save file (Tools > Easy Save 3 > Clear Persistent Data Path) and generate a new one containing just this information, and post it along with the contents of the Assets/Easy Save 3/Types/ folder (if it exists) and the code you're using to save and load.
All the best,
Joel
ScriptableObject fields should be serialized by reference. If you're saying that it's being serialized by value, I've not seen this happen before without the member reference mode being manually set to Value or RefAndValue in the settings.
Please could you delete your save file (Tools > Easy Save 3 > Clear Persistent Data Path) and generate a new one containing just this information, and post it along with the contents of the Assets/Easy Save 3/Types/ folder (if it exists) and the code you're using to save and load.
All the best,
Joel