[NOOB] How do I remove sprite from scene using script?

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

Lets say I clicked a button to remove sprite (not just hide it).

:bust_in_silhouette: Reply From: SIsilicon

Okay okay. n00b ;P.
To remove a sprite with script depends on what node owns the script. If that node is the-

  • Sprite itself, call queue_free().
  • The parent of the sprite, call remove_child('your sprite').
  • Any other node, call 'your sprite'.queue_free().

I maybe over complicating things with the second one. You don’t need to use that one. And the ‘your sprite’ parts are references to the sprite. Which you can get with get_node('relative path to sprite'). To learn more about paths, just visit the Godot docs.