0 votes

Hello,
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 (68 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

Spatial
  - HTTPRequest
     - TextureRect 
by (1,312 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 https://docs.godotengine.org/fr/stable/classes/class_node.html#class-node-method-get-node
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.

0 votes

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

by (68 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 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 webmaster@godotengine.org with your username.