Getting var of parent of area?

Godot Version

4.3 stable

Question

I have two objects. A and B

Object A has a var called power set to 10.0.
It has an area that can overlap other objects.

Object B has a var called power set to 0.0.

inside object B I have this code:

var power : float = 0.0

func _on_area_3d_area_entered(area: Area3D) -> void:
	if area.is_in_group("PowerSource")
		power = area.get_parent().power

however… it says that this cannot be done!

Invalid access to property or key ‘power’ on a base object of type ‘Node3D (script_powerreceiver.gd)’.

Anyone know how to get this var out of object A? :flushed:

Have you spelt the power variable differently in object A?

No. And I hmm wait 5 seconds before it tries to get the Var. So no chance it hasn’t inited yet. Strange.

Is object B getting collisions other than object A? If it is, make sure the script knows that the area_3d.get_parent() has to be object A for it to try and get the power variable.

If I debug and do a
Print(area.get_parent().name)

It yields the correct asset that should have the power Var.

So I guess collision and overlap and all that works.

obj A looks like this:

extends Node3D
@export var power : float = 10.0

it has an area and a collision shape. Both set to “powersource” group.

obj B has an area with collision shape as well. The area scales up and covers the area of obj A every 5 seconds. (this works! since obj B can print the .name of the parent of obj A)

obj B looks like this:

extends Node3D
@export var power : float = 0.0

func _on_area_3d_area_entered(area: Area3D) -> void:
	if area.is_in_group("PowerSource"):
		print(area.get_parent().name)
		power = area.get_parent().power <----------------------------FAILS! :worried:

func _process(delta: float) -> void:
        #doing the things that i dont need to write here, since it works.