The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Before trying a HTTPRequest, I want to simply print the object to change it later (TextureRect).

Scene is simple:
enter image description here

And HTTPRequest script even simplier:

extends HTTPRequest
onready var changery = get_node("TextureRect")
func _ready():
     print (changery)

enter image description here

get_parent works though, but I don't get why get-node is not in this case.
On Ubuntu 21.04

Did you ever have this behavior?

Godot version 3.3.4
in Engine by (66 points)

2 Answers

0 votes
Best answer

get_node() starts looking from node that called it. So, if you calling it from script of HTTPRequest, you are looking for childs of HTTPRequest. And since there is no node named TextureRect as child of your HTTPRequest, it returns null. If you want to make this code work, you need to reparent TextureRect to HTTPRequest, so tree would look like

  - HTTPRequest
     - TextureRect 
by (1,656 points)
selected by

Thanks @AlexTheREgent!
I wouldn't like to change the tree. Only the path.
You're right though that without slash it's a child.

According to
onready var changery = get_node("/root/TextureRect") should work, but it's not.

I accept your reply since I can't honorably accept mine :)

You can also use relative path in get_node like get_node("..") to get parent.

–1 vote

Oh, my, I see my mistake
onready var changery = get_node("/root/Spatial/TextureRect")

by (66 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.