How to Access the parent of the node that instance a scene?

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

Hey,

Before i ask, i look around of an answer but nothing fits my situation, and since i am new to GDScript and Godot in general i dont know what to do.

Here is my world scene structure:

  • World
    – player
    — gun ( has script )

so gun is a child of player , in gun script i instance bullets scene which has the following structure:

  • bullet ( and this has a script )
    -sprite
    -particles2d

Now what i want to do is get the player node position from bullets script. I tried everything but couldnt really find a way to do it.

:bust_in_silhouette: Reply From: duane

The most obvious way I can think of is to put a variable in the bullet script and assign it when you instance the bullet:

In gun:

bullet_instance.var_parent = get_parent()