Can the duplicate() function cause this issue?, so i duplicate the skills and put in in the PlayerInventory but sometimes the variable from subclass is nul
class_name CombatItem extends Area2D
@export var skillName : GlobalEnums.SkillName
@export var weaponName : GlobalEnums.WeaponName
@export var skillType : GlobalEnums.SkillType
@export var skillDescription = ""
@export var skillStatsType : Array[GlobalEnums.SkillStatsType] = [GlobalEnums.SkillStatsType.Damage]
var id = 0
var damage : float = 1.0
var knockbackStrength = 0
var player
func _ready():
if has_node("Hitbox"):
get_node("Hitbox").connect("area_entered", _on_hitbox_area_entered)
get_node("Hitbox").connect("area_exited", _on_hitbox_area_existed)
SignalBus.connect("player_died", PlayerDieDisableObject)
SignalBus.connect("world_ready", OnWorldReadyHandler)
func OnWorldReadyHandler():
player = Global.world.localPlayer
print("PARENT'S PLAYER: " + str(player))
class_name Skill extends CombatItem
var amount : int = 1
var canExplode = false
var isUsed = false
var currentSkillCooldown : float = 0.5
var skillCooldown : Cooldown = Cooldown.new(0, 0)
var flySpeed : FlySpeed
var isPlayerDie = false
func PlayerDieDisableObject():
visible = false
process_mode = Node.PROCESS_MODE_DISABLED
func _process(delta):
print("SUBCLASS'S PLAYER: " + str(player))
SkillBehavior(delta)
Because _process() can be called before the child nodes are ready and have called their _ready().
Guard it by checking if player.is_node_ready(): so you guarantee that’s the case.
thanks for replying but i still don’t know how to do it, where should i use that is_node_ready() function?, the process keep printing the “player” variable is null
Actually i just fixed it, i don’t know if you’ll understand it, my code is a mess but here’s the fix, because the Skill subclass scrippt wasn’t created yet, it was only created when the player chooses a skill, so i need to check it when the script is created, not when the world node is ready.
#In parent class
if Global.world != null:
if Global.world.localPlayer != null:
player = Global.world.localPlayer