How to save a GameObject which is created in runtime ?

Discussion and help for Easy Save 3
Post Reply
raytsang
Posts: 3
Joined: Wed Apr 10, 2019 10:19 am

How to save a GameObject which is created in runtime ?

Post by raytsang »

Hi, I am using a plugin called "TriLib" to load a .fbx file into the scene in runtime.
The model is then set the parent to "GameSceneRoot".
I would like to save all the content under "GameSceneRoot"

Code: Select all

ES3.Save<GameObject>("GameSceneRoot", gameSceneRoot);
save.png
save.png (104.27 KiB) Viewed 3138 times

Code: Select all

ES3.LoadInto<GameObject>("GameSceneRoot", gameSceneRoot);
load.png
load.png (107.28 KiB) Viewed 3138 times
But I cannot get the same model after Load, anyone help ?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to save a GameObject which is created in runtime ?

Post by Joel »

Hi there,

When saving the GameObject, your mesh will be stored by reference rather than by value. So you will need to save the Mesh separately using ES3.Save<Mesh>, as this will save it by value.

For more information I answered a question on this recently:
https://moodkie.com/forum/viewtopic.php?f=13&t=1593

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
raytsang
Posts: 3
Joined: Wed Apr 10, 2019 10:19 am

Re: How to save a GameObject which is created in runtime ?

Post by raytsang »

Thanks for the reply.

For example, the GameObject 'GameSceneRoot' consists of 'RootNode' which got Animation as a component, then the 'Fire_Extinguisher' has 'Mesh Filter' and 'Mesh Renderer'
How can I save all components recursively ?? Thanks
raytsang
Posts: 3
Joined: Wed Apr 10, 2019 10:19 am

Re: How to save a GameObject which is created in runtime ?

Post by raytsang »

Finally, i can get all the components in 'GameSceneRoot'

Code: Select all

        Component[] components = gameSceneRoot.GetComponentsInChildren<Component>(true);
        foreach (Component c in components)
        {
            Debug.Log(c.name + " " + c.GetType().ToString());
        }   
However, I don't know how to save it using ES3.Save<T> as i cannot pass the type to T...

One more question to ask, is it the right direction? Am I suppose to loop a GameObject by myself ?
As I would like to have a simple one line command to save the entire target (GameObject) by purchasing a plugin to do with
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to save a GameObject which is created in runtime ?

Post by Joel »

Hi there,

ES3.Save<GameObject> will save all supported Components on a GameObject. For more info, please see the following guide:
https://docs.moodkie.com/easy-save-3/es ... s-prefabs/

Note that you will need to save each GameObject and child separately as it will not automatically save child GameObjects.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply