Get position (and other methods)/variables for instanced node from other variables

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

-2d node

I create a function to player shoot

const bullet_pre = preload("res://Bullet.tscn") 

func create_bullet(): var bullet = bullet_pre.instance() bullet.global_position = global_position get_parent().add_child(bullet)

But when i add a print(bullet.position.x) just print the inicial moment when the bullet was created, print only once time and no more.
Others variables that change also no print.
I want to know how to print every time how to objects already loaded in node

:bust_in_silhouette: Reply From: Jowan-Spooner

Hi Torico, I think that’s how it should be. A print statement on the end of your function will only be called once. Also, when a functions run is finished all local variables (like your bullet variable) will be erased. If you want to constantly print the states of all bullets of your scene you could add them to a group (bullet.add_to_group(“Bullets”)) and then do something like

func _process(delta):
    for bullet in get_tree().get_nodes_in_group("Bullets"):
        print(bullet.name, " is at ", bullet.position.x)

Hop it helps. Feel free to ask more if not.

That’s right, it worked, thank you so much!!!

Torico | 2019-05-20 02:13

THANK YOU!
After hours of looking for an answer to this, you solved it!
I only made an account on here to thank you,
I really apricate it,
chunkyPug

chunkyPug | 2021-02-12 21:43