How to change objects properties with Area2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DanielsIrTe

Hello, I have been wondering how do i change objects position, size, scale etc. I understand that I need to get path to the node but it dosen’t work for me. And I can’t find any information about this on web. Hope you understand my problem. Have a nice day.

:bust_in_silhouette: Reply From: Zylann

Did you go through all of the official step by step tutorials? Step by step — Godot Engine (stable) documentation in English
They explain the basics, as it sounds like you don’t know how to properly do such basics. And this is surely covered in many places on the web, be it official docs or YouTube tutorials.

This is a question/answer website for specific questions. If you have one, you need to provide more information: scene structure, code you used, where it fails, what error it prints etc. otherwise it’s hard to help you.

Otherwise that’s all advice I can give:
To change position of an area using a path (or any node really) in one line (but there are other ways which might be more common in a real project):

get_node("Relative/Path/To/TheArea").position = the_new_position

Or with the $ shortcut:

$Relative/Path/To/TheArea.position = the_new_position

In projects where the node belongs to a scene and won’t be destroyed, it’s common to cache it in a variable in _ready, using the onready keyword, making the area even quicker to access in the script:

onready var area = $Relative/Path/To/TheArea.position

func _some_function() #Could be _process, _ready, custom func, etc
    area.position = the_new_position

If you got access to a node from a signal like body_entered, you might get the node as a function parameter called body, so again, same syntax:

func _on_Area_body_entered(body):
    body.position = new_position

Of course that’s for position, which is one of many other properties a node can have. The doc lists plenty others you can use. Some of them are nested, in resource etc. but requires you to know how resources work which links back to the basics etc.

But here I’m repeating what I’m sure was said in plenty other places.