In my game I have to have an area 2d connected to the main characterbody 2d so I can detect damage and that area2d has to have its own script because I cant put the get_overlapping_areas function in a characterbody. I was wondering how I would take a variable from my characterbody script and put it in the area2d script so that I can change a variable in the area2d script. How would I do this?

`extends Area2D

var areas = []

func _process(delta: float) -> void:
areas = get_overlapping_areas()
for area in areas:
if area.is_in_group("Good"):
print("Area is working")
elif area.is_in_group("Hurt"):
print("damage")`

From your player script just call "$area.get_overlaping_areas()"

pennyloafers so then how do I call the variables? I put get_parent in a ready function but that doesnt do anything do I put it in the variable itself or what?

    hhll35 what variable do you need to change in the child (area) node? I believe @pennyloafers stated that you have access to the area node from its parent, e.g. the parent body. You can do this using the syntax posted, $area.

    Better still, using the signals present on the area itself (such as area_entered) and handling them in the parent node (which naturally has access to its own properties). You'll code yourself into other problems if the area knows about its parent nodes.

      spaceyjase I am not using the area variable I am trying to get a variable from another script that this area2d node is a child of.

        Can I still have help with this please? this is still an issue

        hhll35 that's what I asked 🙂 The suggestion was to instead use the signals of the area node and connect them to the parent and have the code in the parent modify its own variables. This is the godot way (versus having a child seek data from its parent).

        If you want to do it your way, grab the parent using var parent_node = get_parent() and use the variable parent_node.variable.

          spaceyjase To talk about the first thing you said I cant do that because when I put the get_overlapping_areas code in the parent code it just doesn't work. It isn't a function that exists for the parent object because the parent object is not an area 2d. If you could recommend something that would allow me to put my area2d code in the player code and have it work I'm all ears because I have tried that and it doesn't work.

            hhll35 there's a solution posted, using the get_parent() method in the area node - this should get you the parent reference.

            For the other solution, ideally a signal would be used; e.g. https://docs.godotengine.org/en/stable/getting_started/first_2d_game/03.coding_the_player.html#preparing-for-collisions

            To do this, you can connect the area_entered signal to the character body (that is, the one with the variable that needs changing). godot will generate some code and that's what you put the code to modify the variable. Follow the docs above and change to suit your project, something like:

            func _on_area_entered(area):
                if area.is_in_group("Good"):
                    # code to change the variable
                # the rest of your code

            This goes in the character body.

            To do this in the area node and ignore signals for now:

            func _process(delta: float) -> void:
                areas = get_overlapping_areas()
                for area in areas:
                    if area.is_in_group("Good"):
                        get_parent().your_variable_here # something something
                # etc

            Season to taste. There's quite a lot of information here so please let us know how you get on.

              spaceyjase I think I found a way to combine to code of both the scripts but thanks for the help I appreciate it 🙂