Problems saving references to ScriptableObjects

Discussion and help for Easy Save 3

Re: Problems saving references to ScriptableObjects

Postby Joel » Mon Dec 02, 2019 6:52 pm

Hi there,

If you're planning on returning to the scene where you make objects DontDestroyOnLoad, you might want to consider copy-and-pasting the Easy Save 3 Manager to the other scene instead. You could also try to destroy the duplicate manager when you enter the scene, but I'm not sure how you would guarantee that it is deleted before the manager performs its own checks in Awake().

Just to clarify, Auto Add Manager to Scene simply adds the Manager to the scene. This doesn't guarantee that the dependencies of other scenes have been added to that manager, or that the dependencies have the same instance IDs. So there was no way of the second scene of knowing that the ScriptableObjects existed. You might instead consider whether there is a way of creating the ScriptableObjects in the scene in which they're being used, rather than in the Main Menu. However, this very much depends on your project whether this possible, and the case may be that DontDestroyOnLoad is the only way in your circumstance.

All the best,
Joel
Joel Tebbett @ Moodkie Interactive
Twitter - Unity - LinkedIn
User avatar
Joel
Moodkie Staff
 
Posts: 2552
Joined: Wed Nov 07, 2012 10:32 pm

Re: Problems saving references to ScriptableObjects

Postby Rdbk » Tue Dec 03, 2019 3:52 pm

I tried it with copy-and-pasting, but that didn't work (problem resurfaced) so it seems like DontDestroyOnLoad is the way. The singleton approach indeed didn't work as I got the merging error. I have a script that is created when the game starts and exists until the game is closed. What if ES3Manager gameObject is inactive in editor and I use Start function in that script to turn it on - would this be a suitable solution or do you foresee problems with this? Based on quick testing, it seems to work.

Could you clarify how I could make sure the ScriptableObject is created in the scene to be loaded and not in menu scene? I do not instance these skill SO's at any point and they are just used to store info (which is retrieved through a reference). I have trouble understanding what this "creation" of SO actually means. Does it mean the creation of the object that references these SOs? That object persists through scenes so I assume not.
Rdbk
 
Posts: 25
Joined: Sun Jun 09, 2019 3:58 pm

Re: Problems saving references to ScriptableObjects

Postby Joel » Tue Dec 03, 2019 6:17 pm

Making the GameObject certainly seems like a good way of going about it, and I don't foresee any issues that would be caused as a result of doing that, so that would be your best bet.

Just to clarify my previous comment, I mean instead of declaring your ListOfSkills in the MainMenu scene and then using DontDestroyOnLoad, you declare it in the scene in which you're saving/loading. However, whether this is possible for your project entirely depends on the structure of your project and the purpose of declaring them in the Main Menu, so this might not be applicable to you.

All the best,
Joel
Joel Tebbett @ Moodkie Interactive
Twitter - Unity - LinkedIn
User avatar
Joel
Moodkie Staff
 
Posts: 2552
Joined: Wed Nov 07, 2012 10:32 pm

Re: Problems saving references to ScriptableObjects

Postby Rdbk » Tue Dec 03, 2019 6:58 pm

Ah now I understand, thanks for the clarification! I will think if I could delay the declaration of the list until the next scene.

It seems that changing to one single ES3Manager with DontDestroyOnLoad instead of one per scene wrecked my map saving/loading functionality (I use ES3 to save <Vector3Int, TileBase> Dictionaries, one per TileMap layer and then with loading SetTile on a Tilemap layer by layer - saving and loading is done in a 3rd scene "Battle"). I assume this is also due to mismatch with the references. I will try to play around with this tomorrow if I can come up with a solution. Any ideas for a simple fix? Sorry, it seems I keep creating new problems :)

EDIT: I decided to try saving the dictionary without EasySave3 to reduce dependencies and after a lot of struggling, the results seem promising (managed to serialize one dictionary, save that to json and then print one layer with that json file).
Rdbk
 
Posts: 25
Joined: Sun Jun 09, 2019 3:58 pm

Re: Problems saving references to ScriptableObjects

Postby Joel » Thu Dec 05, 2019 8:29 am

Hi there,

Having a single Easy Save 3 Manager will mean that only the references of one scene will be included in the manager.

Let me know how you get on with the new Dictionary method you speak of :)

All the best,
Joel
Joel Tebbett @ Moodkie Interactive
Twitter - Unity - LinkedIn
User avatar
Joel
Moodkie Staff
 
Posts: 2552
Joined: Wed Nov 07, 2012 10:32 pm

Re: Problems saving references to ScriptableObjects

Postby Rdbk » Thu Dec 05, 2019 7:08 pm

I got the new dictionary method working... except that after restarting Unity, all the loaded maps were scrambled. Oh well. I decided to give the ES3 option another go and refactored my data scripts so that they are created in the scene where they are used. So now I have one ES3Manager per scene (without DontDestroyOnLoad) and so far the loading seems to work properly with the SO's. I also re-refactored my map saving/loading script and it seems to save and load the maps properly (even after restarting Unity).

So HOPEFULLY (please be so :roll: ) everything is working as it should now and I can let this part of the code be as-is. Thanks again for the help! Understanding the significance of when the lists are declared was vital in solving this!
Rdbk
 
Posts: 25
Joined: Sun Jun 09, 2019 3:58 pm

Re: Problems saving references to ScriptableObjects

Postby Joel » Fri Dec 06, 2019 9:35 am

Glad to hear that is (hopefully!) working for you now, let me know if you do come across any other problems :)

All the best,
Joel
Joel Tebbett @ Moodkie Interactive
Twitter - Unity - LinkedIn
User avatar
Joel
Moodkie Staff
 
Posts: 2552
Joined: Wed Nov 07, 2012 10:32 pm

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron