Godot Version
4.2.1.stable
Question
I’m working on a custom Node called DirectionalMovementComponent that’s meant to move a target
Node2D in a direction
. I’m currently using it on a scene that I’ve changed the value of direction
in the inspector to (0, -1). However, whenever the scene is instantiated the value of direction
is reset back to it’s default value. Is there something I’m doing wrong in my scripting or is this a bug?
Here’s the DirectionalMovementComponent script:
class_name DirectionalMovementComponent
extends BaseMovementComponent
## Moves a target Node2D in a single direction.
## Direction target will move in. Will be normalized on set.
@export var direction := Vector2(0, 1):
set = set_direction
func _ready() -> void:
print("ready: " + str(direction))
func _physics_process(_delta: float) -> void:
target.position += direction * speed
print("physics_process: " + str(direction))
func set_direction(value: Vector2) -> void:
value = value.normalized()
print("setter: " + str(value.normalized()))
and the console output:
setter: (0, -1)
ready: (0, 1)
physics_process: (0, 1)
physics_process: (0, 1)
physics_process: (0, 1)