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

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…

           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:

    public int SRBFuel;

and here is the code that does work:

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

which accesses the variables

    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

// 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)

1 Like

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

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