Game Tree wont pause

Hello! I’m a new programmer and I am struggling on making my Scene Tree simply stop if my ball enters an Area2D node. (IN C#), I have tried doing different methods but it just won’t do the job I’m asking it too.

here is the code:

using Godot;
using System;

public partial class Leftgameover : Area2D 
{
	CharacterBody2D ball;
	public override void _Ready() 
	{
		ball = GetNode<CharacterBody2D>("Ball");
		ball.Connect("body_entered", new Callable(this, "OnBallBodyEntered"));
	}
	public void OnBallBodyEntered() 
	{
		if (ball != null) 
		{
			GetTree().Paused = true;
		}
	}
	public override void _Process(double delta) 
	{
		OnBallBodyEntered();
	}
}

I would really appreciate your help, really.

I’d have to guess your ball i not found? Do you get any errors?

Your script is acting like the Ball is a child of the area, but that seems like a bad set up. Can you post your scene tree?


You also try to call this function every frame, by putting OnBallBodyEntered in _process the function will run every frame regardless of collisions.


Your function OnBallBodyEntered does not have a Node2D parameter, so it cannot connect to this function, do you have any errors?

1 Like

Thanks for your Clarification, also the script doesn’t give errors, moreover that the script just doesn’t do its purpose.

I currently can’t send a photo as of right now, but I will certainly review it and fix it from your points, Thank you.

Use method with node parameter,
Check if node is ball, then if it pause game,
You can connect signal with method with +=.

1 Like

Thank you so much!

1 Like