Instantiate ball breaks update

I’m trying to add more lives by instantiating a new ball when it falls down. However, once I instantiate it I noticed it doesn’t run update anymore. I made it work with resetting the position but that does feel a bit hacky. So I’d like to know what is going on.
lose collider was calling the following method on the paddle. It created a ball clone but it didn’t update.

    public void NewBall()
    {
        Vector2 startPostion = new Vector2(7.716f, transform.position.y);
        Instantiate(ball, startPostion, Quaternion.identity);
    }

Hi Arjen,

The new ball needs to be assigned to the paddle.

Before you start challenging yourself, is there a reason why you do not reuse the old ball? You don’t have to destroy it.

1 Like

I did fix it with a transform position for now but in the future I might want to generate more then one ball.
I’m not getting a null btw reference and I see a paddle on the cloned ball.

The below code is in both void start and void awake. I even tried deleting one method and leaving the other.

       hasStarted = false;
        myAudioSource = GetComponent<AudioSource>();
        myRigidBody2D = GetComponent<Rigidbody2D>();
        paddle1 = FindObjectOfType<Paddle>();
        paddleToBallVector = transform.position - paddle1.transform.position;

The reason I think my void update is the problem is that I had a Debug.Log(“running”) in it that stopped once the ball was cloned.

Well done! :slight_smile:


See also:

1 Like

Thanks but I’m still unsure what I’m doing wrong with my instantiate

What do you mean by wrong? Do you get any error messages? When you instantiate a new ball, you need to assign the things you assigned manually in Unity to your former ball via code.

1 Like

I had a Debug.Log(“running”) in update, Debug.Log(“start”) in the start and Debug.Log(“new”) in my awake.

With a new game I would get start and then a million times running. After I lost the ball I got a new but I wouldnt get running anymore.

Is the new ball active in your Hierarchy? Maybe something happened to the new ball after its Start() method had been called.

1 Like


There is a new ball in the hierarchy but it isn’t updating.

What is “ball (clone)” and why are the Circle Collider 2D and Ball components disabled?

1 Like

the ball(clone) is what is instantiated. Not sure why it is disabled. The prefab has it enabled.

Double click on the red error message. There is a variable named collider1. In which line of your code is it?

1 Like

I can’t reproduce that error. I did update the prefab and added the paddle to it. It is linked now but for some reason upon creation the collider and the script are turned off. This is how I call the ball now btw.

public void NewBall()
    {
        Vector2 startPostion = new Vector2(transform.position.x + 7.716f, transform.position.y);
        Ball newball = Instantiate(ball, startPostion, Quaternion.identity);
    }

I did upload my current game btw. If we can find the solution now good if not I’ll get back to it later when I have some more experience. I couldn’t get sharemygames to work so it’s on itch.io
https://alphabravoab.itch.io/bouncer

Could it be that the two components are disabled in the Ball prefab?

1 Like

When I click the prefab that doesn’t seem the case. Paddle is connected to the paddle prefab btw. If I click on a scene it does seem to link to that paddle too.

That looks fine. If it’s not a code issue, remove the object from the prefab field and assign the ball prefab from your Assets folder to it. Maybe the wrong object was referenced.

Thanks. I’ve been able to do it correctly in my new project so the case is closed for me.

(shameless plug)