Weird script behavior

Godot Version

4.2

Question

I’m writing a script for enemy AI and for some reason the execution is failing to read in every frame. For example, I need to get a meta value (Vector3) in every frame and console display like this:

(0, 0, 0)
<null>
(0, 0, 0)
<null>
(0, 0, 0)
<null>
(0, 0, 0)
<null>
(0, 0, 0)
<null>...

My code:

extends CharacterBody3D

@onready var nav_agent = $NavigationAgent3D
@onready var player = %player
@onready var enemy_base = get_parent()

var SPEED = 3.0
var move_speed = 0.0

func update_target_location(target_location):
	nav_agent.set_target_position(target_location)
	
func _ready():
	pass
	
func _physics_process(delta):
	print(get_meta("pin_position"))

Are you sure there aren’t two nodes with the same script in the scene, and one of them doesn’t have the “pin_position” set?

1 Like

You are absolutely right my friend. Thanks for saving me :sweat_smile:

1 Like

A little tip that’s helped me in similar situations, I always add self to my print statements now (you can also use prints or printt to get automatic space or tab delimiting) i.e.

printt(self, get_meta("pin_position"))

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