# Save Script Errors

**URL:** <https://discussions.unity.com/t/save-script-errors/603231>\
**Category:** Scripting\
**Tags:** Scripting\
**Created:** [October 28, 2015, 1:27pm UTC](https://discussions.unity.com/t/save-script-errors/603231 "2015-10-28T13:27:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Roberts](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@Daniel\_Roberts](https://discussions.unity.com/u/Daniel_Roberts)\
**Post date:** [October 28, 2015, 1:27pm UTC](https://discussions.unity.com/t/save-script-errors/603231/1 "2015-10-28T13:27:41Z")

</div>

Hello again,  
I am having a couple problems with my save script again. I was just wondering why it is giving me the errors ‘An Object Reference is required to access a non-static member ‘UnityEngine.Component.transform’’. Also, because of this, it will not let me access any of the scripts in the inspector. Ignore the right part, it is my other screen on the screenshot. Here is my code:

```csharp
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

public class SaveScript {

    public static GameObject player;
    public static GameObject notFound;

    public void Save() {
        BinaryFormatter binary = new BinaryFormatter ();
        FileStream fStream = File.Create (Application.persistentDataPath + "/saves/slot1.byes");

        SaveManager saver = new SaveManager ();
        saver.campos = Camera.transform.position;
        saver.pos = player.transform.position;
        saver.level = Application.loadedLevelName;

        binary.Serialize (fStream, saver);
        fStream.Close ();
    }

    public void Load() {

        if (File.Exists (Application.persistentDataPath + "/saves/slot1.byes")) {

            BinaryFormatter binary = new BinaryFormatter ();
            FileStream fStream = File.Open (Application.persistentDataPath + "/saves/slot1.byes", FileMode.Open);
            SaveManager saver = (SaveManager)binary.Deserialize (fStream);
            fStream.Close ();

            player.transform.position = saver.pos;
            Camera.transform.position = saver.campos;
            Application.LoadLevel (saver.level);
        } else {
            notFound.SetActive(true);
            System.Threading.Thread.Sleep(5000);
            notFound.SetActive(false);
        }
    }

}

[System.Serializable]
class SaveManager {
    public Vector3 pos;
    public Vector3 campos;
    public string level;
}

```

 ![2358338--159891--file.jpg](https://europe1.discourse-cdn.com/unity/original/4X/b/2/2/b223433050822c1f16dd5be17b7f3dcaff504caa.jpeg)

---

<div class="post-metadata">

**Author:** ![gorbit99](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gorbit99/32/551958_2.png) [@gorbit99](https://discussions.unity.com/u/gorbit99)\
**Post date:** [October 28, 2015, 1:58pm UTC](https://discussions.unity.com/t/save-script-errors/603231/2 "2015-10-28T13:58:24Z")

</div>

Camera is a Component, if you want to access the main camera, do Camera.main.transfomr.position. Another option is to assign the camera to a variable as a gameobject and then access the transform
