How to save player gameobject?

I have a player gameobject with child objects (guns which player can pick up). I need to save my player with guns and load it when game starts. Only one solution that I could come up with is to give weapons an ID and then, when loading, give the player a weapon using this ID. Is there a better way to do it?

Nope, that’s one of the better ways to do it.

Generally an unique ID is suggested as it means renaming things won’t break save files.

Same reason why Unity uses a GUID for every asset. It allows us to rename assets without breaking references.

It’s one of the better approaches assuming that you’re not going to have all kinds of variations for the weapon as it lets you save a weapon instance with just a handful of bytes.

You don’t need to assign a random number. Everyone has their own. :stuck_out_tongue:

https://forum.unity.com/members/zulo3d.12023212/

1 Like