0 votes

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 addchild. It doesn't work, but getparent().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)
Godot version 3.4
in Engine by (20 points)

1 Answer

+1 vote
Best answer

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!

by (97 points)
selected by

I got this error

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

Nevermind, it worked :)

I just had to do it like this:

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

Great job!

** THUMBS_UP **

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.