I have a class called Enemy, and a Resource called EnemyStats. I create a new enemy inheriting from the enemy class, and a new resource called test_stats, assign that to my enemy's export variable for the stats.
The Enemy clas script:
class_name Enemy
extends Node2D
@export var stats :EnemyStats
the new enemy's script:
extends Enemy
func _ready() -> void:
print(stats)
This works fine, the enemy can access the stats correctly. I can change the values of the test_stats's max_health in the editor for example and that prints correctly too, all is well.
But if a setter function is assigned to the stats variable int he enemy class, neither the mother class script nor the daughter enemy script can access the stats resource anymore. It always prints as null:
class_name Enemy
extends Node2D
@export var stats :EnemyStats : set = set_enemy_stats
func set_enemy_stats(updated_stats):
pass
Mind you, I didn't come up with the idea of a setter function, i'm following a YouTube tutorial and been experimenting a little with the provided code. Now i've run into this issue and would like to understand what exactly is happening here. What is causing the stats resource to suddenly become null? Do resources just not work right with setter functions?