Creating an instance of a prefab at start?

Hi, I am working on saving and loading gameobjects in my game. I am trying to save the players position and load it up at that particular transform position. I have everything working for objects that do not reference any scripts, but as soon as I try to move my player, I get a ton of errors saying that the player does not exist. I believe it is because of this line of code in particular (in my SaveGameManager script):
public void Load () {

        foreach (SaveableObject obj in SaveableObjects)
            if (obj != null)
                Destroy(obj.gameObject); //This is what destroys my gameobjects before re-instantiating them on 'load'


I have tried telling the Load function instead of destroying the gameobjects, to just move them (like this):

transform.localPosition = obj.gameObject.transform.localPosition;

But this gives me an error relating to this like of code in my SaveGameManager (The error reads “NullReferenceException: Object reference not set to an instance of an object”):

            if (tmp != null) //if we have not already instantiated the object...
                tmp.GetComponent<SaveableObject>().LoadData(value); //instantiate the object

(“tmp” is an array of gameobjects that are ‘saveable’)

Anyone out there that can help me with this issue? I feel like it is right in front of my eyes - I’m just not seeing it.

So you what i am getting is that you have a player standing arround and you want to safe his position, so that on start you have the player right where he was, is that right?

If so it is probably easier to just use this kind of code:

PlayerPrefs.SetFloat("lastXCoordinate", player.transform.position.x);


In my opionion if this is what you want it would be way easier to do it like that.

if you need to set the player on start you just set the transform.x to the PlayerPrefs.GetFloat(“lastXCoordinate”), same with y and z of course.

If i am getting something wrong here what you are trying to do then just tell e right away.

hope this helps anyways!