Page 1 of 1

Load gameobject ignoring instance id

Posted: Fri May 10, 2019 11:28 pm
by tyronleo
Hi. I just purchade EasySave hours ago.
I wrote a little script to save and load a gameobject that have a script with an scriptable object and some other values.
The save is working good, but when I try to "loadinto" another gameobject (B), it doesn't load the script component attached, but change the name of the gameobject (B) and the tag, and it load the information in the main gameobject.
If i delete the main gameobject, EasySave creates a new gameobject called "Easy Save 3 Loaded GameObject", instead of loading the information in the gameobject (B) i use as an argument in the loadinto function.

The Save and load script is this:

Code: Select all

public class Manager : MonoBehaviour
	{
        GameObject player;
        GameObject newPlayer;
        
		void Start()
		{
            player = GameObject.FindGameObjectWithTag("LeoPlayer");
            newPlayer = GameObject.FindGameObjectWithTag("NewPlayer");
		}

        public void LeoSave() {
            ES3.Save<GameObject>("leoPlayer", player);
            Debug.Log("Saved");
        }

        public void LeoLoad() {
            ES3.LoadInto<GameObject>("leoPlayer", newPlayer);
            Debug.Log("Loaded");
        }
    }
The thing i need is to save the script component information in the gameobject and load it in any other gameobject, even in other scene. How to do that?
Any help please? Thanks in advance.

Re: Load gameobject ignoring instance id

Posted: Sat May 11, 2019 9:05 am
by Joel
Hi there,

When loading GameObjects, it's Components are resolved by their reference ID because it's not possible to determine what data belongs to which Component any other way.

If you want to save a GameObject and apply that data to a different GameObject, you will need to save the Components separately and use LoadInto to load the data into the specific Component of the other GameObject.

All the best,
Joel

Re: Load gameobject ignoring instance id

Posted: Sat May 11, 2019 9:32 am
by tyronleo
Thanks a lot :D

I solved it doing this, I don't know if this is the right way:

Code: Select all

public void LeoSave() {
	ES3.Save<Recruit>("leoPlayer", player.GetComponent<Recruit>());
	Debug.Log("Saved");
}

public void LeoLoad() {
	ES3.LoadInto<Recruit>("leoPlayer", newPlayer.AddComponent<Recruit>());
	Debug.Log("Loaded");
}

Re: Load gameobject ignoring instance id

Posted: Sat May 11, 2019 9:33 am
by Joel
Good to hear, that is indeed how I would do it :)

All the best,
Joel