How can I change the settings of a instanced node

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

Hello, the title says all. Here’s my code:

var inimigo = inimigos.instance()
add_child(inimigo)

How can I change the settings(position, scale, etc) via code?
I tried inimigo.position or $inimigo.position, but says “null instance”.

I believe either of the methods you mentioned should work, perhaps something is going wrong when instancing. Are you loading the inigmos resource correctly?

Athakaspen | 2020-07-27 17:11

Is inimigos a node in the scene?

Ertain | 2020-07-27 04:26

:bust_in_silhouette: Reply From: njamster

In theory it’s as simple as:

var inimigo = load("res://inimigo.tscn").instance()
inimigo.position = Vector2(1337, 42)
inimigo.scale = Vector2(1, 2)
add_child(inimigo)

If you get an error about a “null instance”, then you’re trying to access a node that simply doesn’t exist at that point in time! As you have neither posted your full code nor the line number where the error occurs, I cannot help you with that though.