Godot Version
4.3
Question
The _process()
function I have on a child node isn’t being called consistently (or at least isn’t doing what I think it should be doing).
From my understanding the _process()
function attempts to run every frame, but will sometimes not, depending on resources available to it.
I have two classes, a BaseAbility
class and a child dash
class.
The BaseAbility
class is as follows:
class_name BaseAbility
extends Node2D
@export var base_cooldown: float = 1.0
@export var sprite: Sprite2D
@export var ability_name: String
var is_usable: bool = true
var timer := Timer.new()
var time_left: String
func _init():
get_parent().add_child(timer)
timer.one_shot = true
timer.timeout.connect(_on_timer_timeout)
self._ready()
func _process(delta):
if !is_usable:
time_left = "%3.1f" % timer.time_left
print(time_left)
func use_ability(entity):
pass
func start_cooldown() -> void:
timer.start()
is_usable = false
func _on_timer_timeout() -> void:
print(ability_name)
print('ready')
is_usable = true
And its child method dash
:
class_name DashAbility
extends BaseAbility
@export var base_dash_distance: Vector2 = Vector2(40.0, 40.0)
func _ready():
ability_name = "Dash"
base_cooldown = 5.0
timer.wait_time = base_cooldown
func use_ability(entity):
if is_usable:
var current_position = entity.global_position
var facing_direction = entity.last_facing_direction
var new_dash_position = current_position + (base_dash_distance * facing_direction)
entity.global_position = new_dash_position
start_cooldown()
else:
print('on cd')
I’m instantiating a new dash instance on my player, and attempting to call the use_ability
on it, which should teleport the character forward in the direction they’re facing.
The ability works, and has a base cooldown of 5 second as is expected, but the timer.time_left
is counting down normally for the first 2-3~ seconds, then suddenly stops working.
FWIW, the ability cooldown continues to work like normal, only the timer isn’t working the way I would expect it too.
Additionally, _physics_process()
in place of _process()
appears to work perfectly fine, so its something of an interaction between _process()
that is causing the timer.time_left
to behave weirdly.