Godot Version
v4.7.1.stable.steam [a13da4feb]
Question
I thought this might be useful for someone, as I lost some time looking for a solution. I haven’t seen another post about this, in the same context.
I have a parent class, which contained a variable.
extends CharacterBody2D
class_name Monkey
@export var Speed = 400
Then a child class, which inherited the parent class.
extends Monkey
class_name Player
Then, in another script, during physics_update, I tried accessing the said variable.
func Physics_Update(_delta: float):
Player.velocity = movementDirection * Player.Speed
The game would throw an error, saying that the variable is NULL.
Invalid operands ‘Vector2’ and ‘Nil’ in operator ‘*’.
What fixed it for me was specifying the variable type on declaration.
extends CharacterBody2D
class_name Monkey
@export var Speed: float = 400
Have a good day!