Autosave child game object added at runtime to prefab instance created at runtime

Discussion and help for Easy Save 3
Post Reply
irvin
Posts: 9
Joined: Mon Aug 22, 2022 6:54 pm

Autosave child game object added at runtime to prefab instance created at runtime

Post by irvin »

I have a scene with prefabs "Container" and "Item" where I'm trying to add Item as a child of Container at runtime, both have the ES3 Prefab component and I'm using autosave. I've found if I create an instance of Container at run time and then attach an instance of Item then exit, when I load the scene the instance of Item is not attached to Container but is instead loaded at a different location (probably 0,0,0). Now if I have an instance of Container that was created by dragging the prefab into the scene from the editor (i.e. not created at run time) and then attach the instance of Item to it, when I load the the scene the Item instance is attached to the Container instance.

Is there a way to save the parent-child relationship when the parent is created at run time/is the issue that the parent is being created at run time?

Thanks for your help.
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Autosave child game object added at runtime to prefab instance created at runtime

Post by Joel »

Hi there,

In this case the issue is likely because the child is being loaded before the parent (objects are loaded in order of instantiating).

In this case you would need to load twice: once to load all references, and once to ensure that all can be assigned to fields. See the Triggering Auto Save section of the Auto Save guide for information on manually triggering Auto Save to load:

https://docs.moodkie.com/easy-save-3/es ... hout-code/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
irvin
Posts: 9
Joined: Mon Aug 22, 2022 6:54 pm

Re: Autosave child game object added at runtime to prefab instance created at runtime

Post by irvin »

Looks like that worked, thank you!
Post Reply