Invalid access to property or key on a base object of type 'Window'

Godot Version

4.3 stable, Windows 11

Question

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.

Sounds like your hammer was added to the globals list, or to the tree root instead of a child of the hammer attack

1 Like

How do I fix it?

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:
image

This is my hammer projectile:
image

This is my player node, which holds the hammer attack:

And this is my main scene:
image

Globals are defined in the project settings; I would be surprised if it ended up their without your knolwedge.

Is anything being removed or reparented during this action?

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!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.