# An object reference is required for the non static.....

**URL:** https://discussions.unity.com/t/an-object-reference-is-required-for-the-non-static/635964
**Category:** Scripting
**Tags:** Scripting
**Created:** [August 9, 2016, 9:22pm UTC](https://discussions.unity.com/t/an-object-reference-is-required-for-the-non-static/635964 "2016-08-09T21:22:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Tovey-Ansell](https://avatars.discourse-cdn.com/v4/letter/t/5e9695/32.png) [@Tovey-Ansell](https://discussions.unity.com/u/Tovey-Ansell)
#### Post date: [August 9, 2016, 9:22pm UTC](https://discussions.unity.com/t/an-object-reference-is-required-for-the-non-static/635964/1 "2016-08-09T21:22:40Z")

</div>

Yeah, that whole thing, I’m really stumped by this.

I’m trying to access a variable from another class, I’ve done it half a dozen times in other scripts, but for some reason this time it wont work, here’s the code for the one that wont work…

```csharp
           public GameObject Rocket;
           RocketController rocketController;

    void Start()
    {
     
        rb2d = Rocket.GetComponent<Rigidbody2D>();
        rocketController = Rocket.GetComponent<RocketController>();
        PowerSourceText.text = "Power Source: Pad";
        RocketController.SRBFuel = 100; //ERROR HERE
    }

```

and the variable in the other class is:

```csharp
    public int SRBFuel;

```

and here is the code that does work:

```csharp
    void MainEngineStart()
    {
        guiController.startTime = Time.time;
        if (SRBsArmed == true)
        {
            thrustToAdd = guiController.currentThrust = 60000;
        }
//etc

```

which accesses the variables

```csharp
    public int currentThrust;
    public float startTime;

```

I haven’t used the static keyword on either class, yet one works and one doesn’t, as far as I can tell I’ve done both in the exact same way, so what’s different? I’ve assigned all the gameobjects to the scripts with the editor

Any thoughts would be really appreciated, getting pretty frustrated with myself!  
Thanks,  
Fred T.A

---

<div class="post-metadata">

### Author: ![DanielQuick](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/danielquick/32/223057_2.png) [@DanielQuick](https://discussions.unity.com/u/DanielQuick)
#### Post date: [August 9, 2016, 9:24pm UTC](https://discussions.unity.com/t/an-object-reference-is-required-for-the-non-static/635964/2 "2016-08-09T21:24:53Z")

</div>

```auto
// You are using:
RocketController.SRBFuel = 100;

// You should be using:
rocketController.SRBFuel = 100;

```

In one you are using the type (RocketController) and the other is the instance (rocketController)

---

<div class="post-metadata">

### Author: ![Tovey-Ansell](https://avatars.discourse-cdn.com/v4/letter/t/5e9695/32.png) [@Tovey-Ansell](https://discussions.unity.com/u/Tovey-Ansell)
#### Post date: [August 9, 2016, 9:31pm UTC](https://discussions.unity.com/t/an-object-reference-is-required-for-the-non-static/635964/3 "2016-08-09T21:31:23Z")

</div>

Oh for goodness sake 😄 Yes, that works, thanks a lot for the help

…think this is a sign I need to stop coding and go to sleep already
