Error Code: Invalid call. Nonexistent function 'handle_gravity' in base 'Nil'

Godot Version



The title is the error I am getting for my character movement based system. I am new to coding and followed a tutorial to the tee, however, this is the only error I am getting not letting the debug start. So how do I fix it?

Code 1 problem:

extends CharacterBody2D

@export var Input_Component: InputComponent
@export var Gravity_Component: GravityComponent
@export var Movement_Component: MovementComponent
@export var Jump_Component: JumpComponent
@export var Animation_Component: AnimationComponent

func _physics_process(delta: float) → void:
Gravity_Component.handle_gravity(self, delta)
Movement_Component.handle_horizontal_movement(self, Input_Component.input_horizontal)
Jump_Component.handle_jump(self, Input_Component.get_jump_input())
Animation_Component.handle_jump_animation(Jump_Component.is_jumping, Gravity_Component.is_falling)



Accompanying Code (may or may not be needed, I am new):

class_name GravityComponent
extends Node

@export var gravity: float = 1000.0

var is_falling: bool = false

func handle_gravity(body: CharacterBody2D, delta: float) → void:
if not body.is_on_floor():
# Need to multiply by delta when adding to velocity
body.velocity.y += gravity * delta

is_falling = body.velocity.y > 0 and not body.is_on_floor()


Your exported variable isn’t assigned. @export allows you to edit the variable in the inspector for your CharacterBody2D, make sure to fill in the components.

1 Like

if I may ask, fill in components where and how may I get an example or where in the inspector you are doing this because I have all the components attached to the player/characterbody2d from what I know.