Saving Nested Dict/ List of custom classes

Discussion and help for Easy Save 3
c166
Posts: 11
Joined: Sat Sep 03, 2022 2:28 am

Re: Saving Nested Dict/ List of custom classes

Post by c166 »

Hey Joel,

Didn't expect to have to come back so quickly -> but I've bumped into related issues.

So everything appears to work in edit mode (i.e. everything loads) -> but when I tested using build mode -> the problems that were resolved (missing sprites + effects) seems to have come back.
easy_save_build_mode_problems.PNG
easy_save_build_mode_problems.PNG (362.06 KiB) Viewed 1472 times

Code: Select all

ArgumentException: The Object you want to instantiate is null.
  at UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) [0x00009] in <f96c34788b094e3c84c2515f70a061aa>:0 
  at UnityEngine.Object.Instantiate[T] (T original) [0x00001] in <f96c34788b094e3c84c2515f70a061aa>:0 
  at CCGKit.PlayAnimationAction.Execute (UnityEngine.GameObject go) [0x0000d] in E:\Unity\Asset Testing\Single Player CCG\CCG Mod\Assets\SinglePlayerCCGKit\Scripts\Actions\PlayAnimationAction.cs:26 
  at CCGKit.EffectResolutionSystem.ResolveCardEffects (CCGKit.RuntimeCard card, CCGKit.CharacterObject playerSelectedTarget) [0x00169] in E:\Unity\Asset Testing\Single Player CCG\CCG Mod\Assets\SinglePlayerCCGKit\Scripts\Systems\EffectResolutionSystem.cs:165 
  at CCGKit.CardWithArrowSelectionSystem.PlaySelectedCard () [0x00019] in E:\Unity\Asset Testing\Single Player CCG\CCG Mod\Assets\SinglePlayerCCGKit\Scripts\Systems\CardWithArrowSelectionSystem.cs:159 
  at CCGKit.CardWithArrowSelectionSystem.DetectEnemySelection () [0x00070] in E:\Unity\Asset Testing\Single Player CCG\CCG Mod\Assets\SinglePlayerCCGKit\Scripts\Systems\CardWithArrowSelectionSystem.cs:119 
  at CCGKit.CardWithArrowSelectionSystem.Update () [0x00060] in E:\Unity\Asset Testing\Single Player CCG\CCG Mod\Assets\SinglePlayerCCGKit\Scripts\Systems\CardWithArrowSelectionSystem.cs:63 
It seems that certain things were not loaded into the scene (build version). Though the items seem similar enough to the things that were not loaded in the scene (editor version) which were fixed by adding them to EasySave Reference Manager.

Is there something that needs to be done in addition for the build version?/ Any idea as to what may be the cause of this?

Best Regards,
C
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Nested Dict/ List of custom classes

Post by Joel »

Hi there,

I’ve not seen this happen before. Please could you replicate this in a minimal project and private message it to me with instructions so I can see what is happening?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
c166
Posts: 11
Joined: Sat Sep 03, 2022 2:28 am

Re: Saving Nested Dict/ List of custom classes

Post by c166 »

Hey Joel,

I'll see if I can replicate it in a minimal project but it may take a while to do so. I have asked the asset owner (building off another asset from the Unity Store) about whether they'd be okay with me sharing their code/ base asset.

In the mean-time I think I've worked out the mechanism behind why that's happening (and so it may be quicker for me to try to brute force it as far as I can based on your advice -> until I hit a show-stopper at least -> which may be soon tbh haha).

It seems that when I do the SAVE action in-game (build mode) - EasySave creates a new set of AssetReferences as opposed to using the ones that exist in the other scene. When saving in Editor mode -> the SAME AssetReferences BETWEEN scenes are generated/ used.
If your object exists outside of a scene (i.e. it's an Asset such as a ScriptableObject in a folder), Easy Save has internal logic which ensures that the same ID is generated regardless of scene so that cross-scene references are possible.
I think that this internal logic may have some slight differences between Editor/ Build mode? Or I'm missing some steps that are required for this link to be established in build mode. Any idea?

If you could also point me to where that internal logic is -> I could have a crack at trying to understand/ get a better idea of what's happening.

E.g. The rarity reference id created in Build Mode is:
  • 5615321483582845591 (does not exist)
If the rarity reference is created in Editor Mode (uses existing references as expected):
  • 5696394823885153397
  • 7721319610198785470
  • 3079034528638927938
These are log errors that occur once I save in the deck page and then move into the game page (Missing Asset References)
NewAssetReferences_BuildMode.PNG
NewAssetReferences_BuildMode.PNG (29.03 KiB) Viewed 1469 times
I found that these asset references did not match with the ones saved in the EasySave3 Reference Manager in the scene (At least in Editor Mode). I focused on CardRarity as there were only 3 of them.

The references for Editor Mode (game page) are:
EasySave_References_EditorMode_GameScene.PNG
EasySave_References_EditorMode_GameScene.PNG (9.82 KiB) Viewed 1469 times
When I save in Editor Mode (deck page); the SAME AssetReferences are generated:
EasySaveReferences_EditorMode_DeckSaveScene.PNG
EasySaveReferences_EditorMode_DeckSaveScene.PNG (25.25 KiB) Viewed 1469 times
It also seems like when I wipe the save (clear EasySave data) -> the build mode creates new (random) asset references on Save -> so from the perspective of that scene, it appears to think those assets are new/ does not exist anywhere.

I have tried to go into the game scene first -> back out and then go to the deck scene to save the asset references (testing whether "loading the scene where the asset references are saved" before "saving" the assets in another scene would help establish the link). Unfortunately that did not work.

Best Regards,
Clement
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Nested Dict/ List of custom classes

Post by Joel »

Hi Clement,

It sounds like an asset external to Easy Save is creating new references at runtime, though I’m not sure why. However, a basic project should demonstrate this so we’re can see what is happening when you get permission to create one.

The logic is in ES3ReferenceMgrBase.cs and ES3ReferenceMgr.cs, though the logic around cross-scene references is quite simple. When gathering scene references it will check a List of assets (ES3GlobalReferences.cs) for that asset. If it exists in that list, it will use the ID from that list. If not, it will generate a new ID and add it to the global references list.

If when loading a reference with that ID doesn’t exist, it either means that the object has been generated at runtime, or the object isn’t a dependency of that scene so never gets added to the manager (though this wouldn’t explain why it works in the Editor and not in the build).

Just to check, are you on the latest version of Easy Save?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
c166
Posts: 11
Joined: Sat Sep 03, 2022 2:28 am

Re: Saving Nested Dict/ List of custom classes

Post by c166 »

Hey Joel,

The version of EasySave I am using is "Version 3.4.2 - April 24, 2022" which seems to be the latest version.

Unfortunately, I got the response of
Generally speaking, you cannot redistribute the contents of the kit to third parties without them having an appropriate license as well.
Do you happen to have a copy of "Single-Player CCG Kit" (https://assetstore.unity.com/packages/t ... kit-150156)?

If you don't -> I'll go back to their help team to see if an exception of some sort can be made.

Best Regards,
Clement
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Nested Dict/ List of custom classes

Post by Joel »

Hi Clement,

Unfortunately we have no knowledge of that asset and do not have a copy.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
c166
Posts: 11
Joined: Sat Sep 03, 2022 2:28 am

Re: Saving Nested Dict/ List of custom classes

Post by c166 »

Hey Joel,

I have asked the asset owner if they'd be able to make an exception for me to create a minimum build/ share the code with you.

In the meantime, if you've got ideas for me to try - that'd be great. Can you clarify what "being generated at RunTime" means?? Does it mean that things are being generated procedurally/ randomly?

From the below image you can see that some assets load, but others do not.
EasySave_PartialLoadingOfAssets.PNG
EasySave_PartialLoadingOfAssets.PNG (338.15 KiB) Viewed 1403 times
In particular, the ones that require additional animations (e.g. call an explosion or shield animation on attack) are the ones which do not work (i.e. the animation is missing). I assume that it is missing the explosion sprite (or it's been saved under a different reference).

In contrast, the animations that don't require the generation or "calling" of any animation effects (i.e. moving the character on attack works)

This is what it's meant to look like:
EasySave_NormalLoad.PNG
EasySave_NormalLoad.PNG (227.34 KiB) Viewed 1403 times
The sprites are static (i.e. the same sprite/ icon is being used for each "card" that is of the same type). So the images are not being "procedurally" generated.

I suspect it may be related to the sprites/ textures warning that I receive when I'm saving the assets.
Easy Save cannot save the pixels or properties of this Texture because it is not read/write enabled, so Easy Save will store it by reference instead. To save the pixel data, check the 'Read/Write Enabled' checkbox in the Texture's import settings. Clicking this warning will take you to the Texture, assuming it is not generated at runtime.
From the shield icon + lowered health, you can see that SOME of the effects go through. The shield icon is a sprite being generated -> though it involved no animations/ animated components.
EasySave_PartialEffects.PNG
EasySave_PartialEffects.PNG (135.08 KiB) Viewed 1403 times
Hoping you've got some ideas that I can try while we wait for the response from the asset owner/ creator re. sharing.

Best Regards,
C
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Nested Dict/ List of custom classes

Post by Joel »

Hi there,
c166 wrote: Sat Oct 01, 2022 1:45 am In the meantime, if you've got ideas for me to try - that'd be great. Can you clarify what "being generated at RunTime" means?? Does it mean that things are being generated procedurally/ randomly?
This means that the object is being instantiated or copied at runtime (for example, using Unity's Instantiate method). Textures/Sprites are also sometimes copied when a renderer's 'sprite' or 'texture' field is accessed rather than using it's 'sharedTexture' field.
In particular, the ones that require additional animations (e.g. call an explosion or shield animation on attack) are the ones which do not work (i.e. the animation is missing). I assume that it is missing the explosion sprite (or it's been saved under a different reference).
Animations aren't serializable at runtime, so this could potentially be the issue. In your case it shouldn't be necessary to save the animation itself anyway as this doesn't appear to be created at runtime. Have you created any ES3Types in Types window which are trying to save/load this Animation?
Easy Save cannot save the pixels or properties of this Texture because it is not read/write enabled, so Easy Save will store it by reference instead. To save the pixel data, check the 'Read/Write Enabled' checkbox in the Texture's import settings. Clicking this warning will take you to the Texture, assuming it is not generated at runtime.
This would definitely cause the behaviour you're experiencing because it's impossible to access the Texture data without the Texture being readable. In this case you would need to make it readable. However, in most cases you shouldn't need to save and load the Sprite itself and this can be quite computationally expensive. For complex GameObjects you should only save and load the aspects of the GameObject which will change at runtime.

Unfortunately it's not possible for me to provide advice on how to proceed without a basic project which replicates it.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
c166
Posts: 11
Joined: Sat Sep 03, 2022 2:28 am

Re: Saving Nested Dict/ List of custom classes

Post by c166 »

Hey Joel,

Just wanted to say that I managed to resolve the problem following some advice from the asset kit creator.

I ended up saving the ids of the scriptable objects + creating a new instance of that object in the other scene instead of trying to save the game object itself. That turned out to be a lot more straightforward than what I was originally trying (which I'd turned to as it worked in other areas -> within the same scene)

Anyway, thanks again for your help - process has helped me get a better understanding of how EasySave works + when/ when not to use it (i.e. I will try to avoid saving gameobjects directly when they need to be referenced cross-scene since for items which need access to animations/ textures)

Best Regards,
C
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Nested Dict/ List of custom classes

Post by Joel »

Glad you managed to get that working :)

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