I'm getting the "Invalid get index 'global_position' (on base: 'null instance')" error

Godot Version

Godot 4.2.1


I’m following LegionGames’ tutorial on pathfinding and I’ve seem to run into an issue. Whenever I run the game, it gives me the error I specified in the title. I’ll paste the code here

extends CharacterBody3D

@onready var player = null

const SPEED = 6.0

@export var playerPath : NodePath

@onready var audioPlayer = $AudioStreamPlayer3D
@onready var chaseMusic = $Chasemusic
@onready var animationPlayer = $AnimationPlayer

@onready var navAgent = $NavigationAgent3D

func _ready():
	player = get_node(playerPath)
func _process(delta):
	velocity = Vector3.ZERO
	var nextNavPoint = navAgent.get_next_path_position()
	velocity = (nextNavPoint - global_position).normalized() * SPEED

func _on_area_3d_body_entered(body):
	if body.name == "Player":

func _on_area_3d_body_exited(body):
	if body.name == "Player":

Now the thing is, I believe it’s because of NodePath, but I really don’t know. Keep in mind, I am new to Godot and its language.

Export keyword means that you have to set the value in the inspector. Did you do so?

I did not, thank you for reminding me, I completely forgot to do that lol.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.