Serialize, deserialize and keep references alive


I am working on a software, that needs to serialize and deserialize a loot of objects. Those objects will be removed when serialized, and later they will be added again by deserializing the data.
I now want to reestablish all references pointing on the object when it is recreated.

Given the example with object A that holds a reference on object B:
When I serialize and destroy B, the reference will be broken.
Some time later, I recreate B and want the reference from A to B to be recreated.

Can someone tell me, how I can reestablish the reference from object A to object B?
Is there a fast way to get all references in the scene pointing on a certain object?

I’m using C# and Unity free.


The simples solution would be to add a new component which creates a GUID for each object. When you save out the object references, save out the GUID of the referenced object. When you load the object reference, try to find an object with your component whose GUID matches and fixup the reference. Done!