+3 votes

Hello,
i have a function which add a pausemenu to the scene(instance) which is triggered by a button press or a quit request(notification)
the function seems to run well when triggered by the button but when its triggered from the quit request the instance isn't added to the scene...

function:

func _on_pause_button_pressed():
    if(disablepause==false):
        var cam_pos = get_node("Camera2D").get_pos()
        var pause_menu = pause_class.instance()
        pause_menu.set_pos(cam_pos)
        add_child(pause_menu)
        get_node("sound_effect").play("button_clicks")
        pause_menu.pause_game()

_notification function:

   func _notification(what):
        if(what == 7 and get_tree().is_paused() == false):
            _on_pause_button_pressed()
            print("quit request")

i tried calling addchild on getparent() and a specific node in the scene but it wont seem to work
I'm using Godot version 1.1 stable, is this a bug that has been fixed in the newer version or am i doing something wrong

in Engine by (38 points)

Same error on Godot 2.0.

enter image description here

2 Answers

+2 votes
Best answer

Answered by Mariano Suligoy and Juan Alpaca :
to add a node inside a notification use calldefferred, so the node will be added when the idle frame ends:
call
deferred("addchild",pausemenu)

by (38 points)
0 votes

Add this:

func _ready():
    get_tree().set_auto_accept_quit(false)

The auto_accept_quit from project settings doesn't work.

If auto_accept_quit is true, application runs your code (you should be able to see "quit request" message in console and maybe in debugger) and closes the app instantly after it's done.

by (84 points)
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 Frequently asked questions and 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 [email protected] with your username.