Hello,
I am trying to create a burning status effect for my game. What I have made for this is a node that will be placed in a character, create particles, and deal damage to its parent over time. I have a problem where when the player’s attack, a fireball, hits the enemy, it does not properly reparent the status effect into the enemy. It says,
![]()
This is my code for the fireball:
extends CharacterBody2D
class_name Player_Projectile
@export var frost_flame: bool
@onready var frost_texture = preload("res://assets/projectiles/cannon_one_bullet_m2.png")
@onready var flame_texture = preload("res://assets/projectiles/fireball_projectile.png")
@onready var flame_status = preload("res://scenes/fx/fire_status.tscn")
@onready var sprite = $Sprite2D
@onready var anim_player = $AnimationPlayer
var max_scale = 15
var damage_multiplier: int = 1
var damage = 2
var living_bullet = true
const SPEED = 50
const SIZE_GAIN = 100
func _ready() -> void:
anim_player.play("spawn")
velocity = Vector2.ZERO
if frost_flame:
if randi_range(0,1) == 0:
sprite.texture = frost_texture
else:
sprite.texture = flame_texture
else:
sprite.texture = flame_texture
func _process(delta: float) -> void:
if scale <= Vector2(max_scale,max_scale):
scale+=Vector2(SIZE_GAIN*delta,SIZE_GAIN*delta)
sprite.rotation += 0.5
global_position += transform.x*SPEED*delta
move_and_slide()
var collide = move_and_collide(Vector2.ZERO)
if collide:
var collided_with = collide.get_collider()
if "health" in collided_with:
if collided_with.attackable == true:
if living_bullet:
if not "fire" in collided_with:
var new_flame = flame_status.instantiate()
new_flame.reparent(collided_with)
collided_with.health -= damage*damage_multiplier
collided_with.attackable = false
queue_free()
else:
queue_free()
queue_free()
func _on_dissipate_timer_timeout() -> void:
queue_free()
and if it might help, the code for the status effect is the following:
extends Node2D
@onready var flame_fx = $flame_fx
@onready var smoke_fx = $smoke_fx
@onready var timer = $Timer
var parent
var ticks_done = 1
func _ready() -> void:
parent = get_parent()
timer.start()
func _on_timer_timeout() -> void:
print(ticks_done)
if parent:
if "health" in parent:
if ticks_done < 3:
parent.health -= 1
ticks_done += 1
elif ticks_done >= 3:
smoke_fx.emitting = false
flame_fx.emitting = false
func _on_dissipate_timeout() -> void:
queue_free()
The error says that the enemy is null, but that confuses me because the attack is able to initially do damage to the enemy.