Godot Version
4.2.2
Question
I designed the behavioral tree for my enemy, designed its death logic.
var disappear: bool = false
func tick(_delta: float) -> BehaviorNodeState:
if character.status.health <= 0:
if disappear:
character.queue_free()
return BehaviorNodeState.RUN
return BehaviorNodeState.SUCCESS
func _on_visible_on_screen_enabler_2d_screen_exited() -> void:
disappear = true
The tick() will be called in _physics_process(). When the return state is RUN, the next frame will continue to execute this tick(), otherwise the next logic is executed.
In my design, the death of a character removes its collision, allowing it to fall out of the screen, it will be removed after it disappears from the screen.
But I found that after leaving the screen, the character’s logic is suspended and quene_free() doesn’t trigger as expected.
This also happens with other logic, such as patrolling, where if it leaves the screen, it freezes in place and won’t return until the camera captures it again.
How do I get it to work even when I’m away from the screen? If this is an important way for Godot to optimize for performance, are there other elegant solutions?