[SOLVED] RigidBody2D.gravityScale is not updating the instance at runtime

Hello everyone.

I have spent most of the day trying to simulate an increase in gravity on a ball in my little 2D breakout game. Its basic stuff that I want to do so I wish to check the right way to go about it.

I tried to increase the Gravity Scale on the Balls Rigid Body at runtime but the ball is ignoring the value. If I stop the game and run it again I see the new value reflected in the Inspector and it gets applied but only if I stop and start the game. Is there anyway to actually invoke the change at runtime?

Here is the code for my my Ball.

    public void IncreaseBallGravity()
        {


        float ballGrav = GetComponent<Rigidbody2D>().gravityScale;  //load ballGrav with the current ball gravity
        
        ballGrav++;                //increment ballGrav

        print("ballGrav = " + ballGrav);

        GetComponent<Rigidbody2D>().gravityScale = ballGrav;
       
        }

I have also looked at Physics.gravity in the Unity docs but I am unsure if this is what I want.
I have tried to use Physics.gravity like so

GetComponent<Physics2D>().gravity

but intellisense does not like.gravity so I know I am doing it wrong. I have tried looking online and I hear mention that Physics.gravity being a global thing so I came to ask what I should use to achieve this.

I wish to be able to change the gravity of a specific object at runtime and get the same effect as changing as I do when I increase the RigidBody2D Gravity Scale before starting the game.

Thanks for any help you can give.

Okay so it looks like my Prefab for the ball IS actually changing but my instance is not so i’m obviously referencing the wrong thing. Just need to work out what!

EDIT:

theBall = GameObject.FindObjectOfType<Ball>();

from the script calling the ball script. It was indeed acting on the Prefab object and not the instance!