Fluxistence Posted October 4, 2021 Share Posted October 4, 2021 How would you go about saving a reference in a component to an entity that has a parent from outside said parent? Inventory items, for example. From what I've seen, when you pick up an inventory item or put it in a container, its parent is set to whatever is holding it (the player's inventory or the container). This makes the game exclude it from the list of saved entities (see SaveGame() in mainfunctions.lua). This means that if you return a that entity's GUID as a requested reference on OnSave(), you get a missing reference error in the log and that entity will not be available by that GUID in the list of entities during LoadPostPass(). The inventory/container apparently deals with this by manually saving their contents using GetSaveRecord() during saving and then creating the entity with SpawnSaveRecord() during loading. You can't do this elsewhere though, since you'd need the reference to the entity that the inventory/container spawns, rather than spawn an entity of your own. So... what's the right way to do this? I used a workaround which I think is pretty ugly, so although it works I'd still like to know if there's a better way to accomplish this goal. Link to comment https://forums.kleientertainment.com/forums/topic/134193-saving-references-to-parented-entities/ Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now