In my game, I have a “hammer attack” node to be used as an attack by the player character. This node instantiates “hammer projectile” nodes, which are what actually makes contact with the enemies.
The hammer attack node has this code in it:
var dir = get_angle_to(get_global_mouse_position())
var hammer = hammer_scene.instantiate()
add_child(hammer)
hammer.rotation = dir+(2*PI*i)/howmany
And in my hammer projectile script, I try to get a bunch of stat values from the attack node using onready:
extends CharacterBody2D
@onready var damage = get_parent().base_damage * get_parent().damage_multiplier
@onready var rangestat = get_parent().rangestat_r
@onready var pierce = get_parent().pierce_r
###and on and on
This used to work as intended with no issues. However, after coding a different weapon into the player’s arsenal, and not changing anything in the hammer code, suddenly I get this error:
Invalid access to property or key 'base_damage' on a base object of type 'Window'.
I tried using print(get_parent()) in the hammer projectile’s _ready() function, and the parent is a node2D, not a window. So why is get_parent() returning a window? And what can be done to fix this? Any help is appreciated.
Could you provide more information, like which of the two problems listed was correct? For both of them a solution would be to ensure the hammer is only added as a child of something with base_damage etc. Could you post your scene tree?
I don’t know what the “globals list” is, I tried googling it to no avail. Could you be referring to the “access as unique name” property? That is not enabled in my hammer node.
I’m not really sure if it being added to the tree root is correct either, because, as I explained, using print(get_parent()) returns a Node2D. Both my main scene node and my hammer attack node are Node2Ds, but neither of them is a Window.
This is my hammer attack:
This is my hammer projectile:
This is my player node, which holds the hammer attack:
I figured out the issue. Another player weapon I had been developing, which used copied code from the hammer weapon, was trying to instantiate hammer projectiles instead of its own projectiles. I simply forgot to change the directory from the hammer directory to the intended directory when I copied the code. I changed it and it’s fixed now. Thank you for your help!