Cross-scene references

Discussion and help for Easy Save 3
Post Reply
KEM4
Posts: 6
Joined: Mon Mar 22, 2021 9:07 am

Cross-scene references

Post by KEM4 »

Hello.

Well, this hit me hard on realization and took longer than I wish for. This is not an intention to blame but would like to understand the concept idea and how to possibly solve it.

Scenarion:
SceneA and SceneB has their Reference Managers attached and afaik it loads the references per scene. Meaning if I have refId or rA on sceneA I cannot get the same refId on SceneB? Tried it out with saving the value on SceneA and then on SceneB tried to find by that same ID and indeed it does return null.

Question:
How do I approach reference saving in cross scenes?
The main idea behind it is that I want to attach/detach certain "consumable" that is a reference to scriptable object in SceneB but also show it in SceneA that I have it.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Cross-scene references

Post by Joel »

Hi there,

It's not possible to get a persistent reference to an object in a scene from another scene, because it would be impossible for Scene B to know about an object in Scene A prior to runtime. This is a limitation with Unity rather than at our end.

Generally in this circumstance you would create your own static manager of these ScriptableObjects, and associate your own unique ID with each ScriptableObject. Then instead of saving and loading the ScriptableObject itself, you save it's unique ID. You can then use this unique ID to look up the ScriptableObject in your static manager and get the instance, regardless of what scene you are in.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
KEM4
Posts: 6
Joined: Mon Mar 22, 2021 9:07 am

Re: Cross-scene references

Post by KEM4 »

Yes I am moving this towards that solution of using uuid + repository pattern and then upon loading I firstly have reference table (repository) and lookup the table to assign the reference.

Thanks for the clarification there and seem that I used best out of what could be done here.
Post Reply