Godot Version
4.2
hello i am trying to code a way for a pong paddle to get bigger or smaller acording to its health function the only way i could think to do this is by having a buch of paddle segment that i would use the remove child function to hide and then the add child function to add back but every time i call the add child function the game just crashes
here is the code im using
extends CharacterBody2D
@export var speed = 200
var health =3
func get_input():
var input_direction = Input.get_axis(“left”, “right”)
velocity.x = input_direction * speed
func _physics_process(_delta):
get_input()
move_and_slide()#how i control paddle movement ^
if health <= 4 :
remove_child($paddlesegement5)
if health <=5 :
add_child($paddlesegement5)
if Input.is_action_just_pressed(“test input”):
health = health +5
and here is the error i get
E 0:00:03:0229 paddle.gd:14 @ _physics_process(): Parameter “p_child” is null.
<C++ Source> scene/main/node.cpp:1600 @ remove_child()
paddle.gd:14 @ _physics_process()
E 0:00:03:0229 paddle.gd:14 @ _physics_process(): Node not found: “paddlesegement5” (relative to “/root/main level scene/Paddle/Paddle”).
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1792 @ get_node()
paddle.gd:14 @ _physics_process()
any help solving the errors or telling me a smarter way to do what im trying to do would be much apreciated