add_child problem

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

I have a problem with this. I’m new here. I just wanted to make a pause screen and then I got a problem with add_child. It doesn’t work, but get_parent().remove_child(self) works. It successfully removed the child.

Pause script:

func _process():
    if Input.is_action_just_pressed("ui_accept"):
        get_parent().remove_child(self)
        var options = load("res://options.tscn").instance()
        add_child(options)
:bust_in_silhouette: Reply From: Wolchy

Hi!

Make the following changes to the line where you want to add a child node:

self.get_parent().add_child(options)

I hope it will help you. Good luck!

I got this error

Attempt to call function ‘add_child’ in base ‘null instance’ on a null instance.

Potato_Boy_34 | 2022-01-06 21:57

Nevermind, it worked :slight_smile:

I just had to do it like this:

self.get_parent().add_child(options)
get_parent().remove_child(self)

Potato_Boy_34 | 2022-01-07 11:48

Great job!

** THUMBS_UP **

Wolchy | 2022-01-07 14:57