# How do I implement references or relations for entities within a serialized savegame?

I have a 2D tile based RPG for which I'm developing save game function. In particular, I'm trying to save this structure:

A caster can have multiple buffs that he maintains. Each buff can have multiple effects applied to players or monsters. The pattern has links both ways (caster has buff, buff knows who cast it)

If I serialize caster, buffs and effects, how can i restore the relationship: caster - buff - effect - target?

Would I need to implement something like unique identifiers for monster, buffs and players and then link them all together once the save game is loaded?

• I don't think the question needs details of your iOS implementation. If you need to add more info to your question to get better information, you can do that, but as far as I could tell your edit was extra information that wasn't needed. – MichaelHouse Jan 5 '14 at 18:54
• Related (possible duplicate?): gamedev.stackexchange.com/questions/68254/… – user1430 Jan 5 '14 at 19:02
• I think related for sure. That question is asking about what type of data to use for identifying references between assets, this question is asking about how to maintain references between components and entities when writing/reading them to disk. So, we can use the information from that other question and apply it here, but the other question doesn't answer this one. – MichaelHouse Jan 5 '14 at 19:07

Unique identifiers are a good option. However, they don't need to be used in game, only when writing and then reading the data from a save. Hopefully you'd already have some way to differentiating between entities you can use, otherwise you can make something up (typically an int or long)