Giving script to parent

Godot Version

4.2.2

Question

so sorry if this is a little confusing to explain i will try my best

i want to have two nodes 1 being the parent node and another a blank node. The blank node would have a script attached to it and then have the script attached to the node be applied to its parent node.

Is this possible ? if so how do i go about it

You can do this sequence:

get_parent().set_script(get_script())

get_parent() returns a parent Node
set_script() sets a specified script to the Object
get_script() returns a script from the current Object
Combination of these should give you your desired effect.
But you need to be careful, as this script might propagate up through your whole SceneTree. You may want to steer this script-changing-processing from a different Node that doesn’t take place in the process.

2 Likes

Can you explain the use case a bit more, as it is almost certainly a better idea for the parent to manage it’s children.

4 Likes

so o i made a lil thing but basically i just want to attach scripts to blank nodes then put those nodes as children to something like the player character this way i can pick and choose what entity has what scripts/

ex:

ex:

1 Like

thanks i will remember that

The issue with your idea is that a Node can have only 1 script attached to it, no more.
What you described is basically Entity Component pattern, which is described e.g. here:

And many other places, including YT. Look up some tutorials, as this topic has been discussed plenty of times already :slight_smile: if you need any support - open a topic here again.

2 Likes

Thanks for the help!
Ill check out some stuff out and reply if I have any questions!

2 Likes