Godot Version
Godot 4.4.1 stable
Question
Hello,
I am following the HeartBeast Space shooter tutorial.
The goal is to create a more complex enemy behavior cycling components.
Move to on the y axis for 2s, then move on the x axis, then spawn projectile, then pause, then start again.
However, when the code projectile_spawner_component.spawn(pink_enemy.global_position)
is added, I am met with a ‘Cannot call method “translate” on a null value.’ pointing me to the move_component.
Please note that the projectile is spawning is executed, it is when the inline function is finished that the error pops up. Also note that commenting out the projectile_spawner_component.spawn(pink_enemy.global_position)
gets rid of the error.
Also note that the original tutorial is 2 years old and was developed on Godot 4.1.3, that is why I believe that the error might be due to some engine version differences.
Please see the script of the enemy as well as the script that the error points towards.
pink_enemy
class_name PinkEnemy
extends Enemy
@onready var states: Node = $States
@onready var move_down_state: TimedStateComponent = %MoveDownState
@onready var move_side_state: TimedStateComponent = %MoveSideState
@onready var pause_state: TimedStateComponent = %PauseState
@onready var move_side_component: MoveComponent = %MoveSideComponent
@onready var fire_state: StateComponent = %FireState
@onready var projectile_spawner_component: SpawnerComponent = %ProjectileSpawnerComponent
@onready var pink_enemy: PinkEnemy = $“.”
func _ready() → void:
super()
for state in states.get_children():
state = state as StateComponent
state.disable()
move_side_component.velocity.x = [-20, 20].pick_random()
move_down_state.state_finished.connect(move_side_state.enable)
move_side_state.state_finished.connect(func():
fire_state.enable()
scale_component.tween_scale()
projectile_spawner_component.spawn(pink_enemy.global_position)
fire_state.disable()
fire_state.state_finished.emit()
)
move_side_state.state_finished.connect(pause_state.enable)
fire_state.state_finished.connect(pause_state.enable)
pause_state.state_finished.connect(move_down_state.enable)
move_down_state.enable()
func _process(delta: float) → void:
pass
move_component.gd
class_name MoveComponent
extends Node
@export var actor: Node2D
@export var velocity: Vector2
func _process(delta: float) → void:
actor.translate(velocity * delta)
Any help is welcome, I have fried my brains on this one.