0 votes

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".

in Engine by (171 points)

Is inimigos a node in the scene?

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

1 Answer

+1 vote
Best answer

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.

by (10,261 points)
selected by
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.