Reputation: 23
I am making a game in godot. But I can't unpause after pausing. I used Input Map to create two keyboard shortcuts(one to pause and other to un-pause) and auto-loaded the script. This is the code:
extends Node
var players_coin = 0
func _ready():
PAUSE_MODE_PROCESS
func _input(event):
if Input.is_action_pressed("pause"):
get_tree().paused = true
if Input.is_action_pressed("unpause"):
get_tree().paused = false
I am bad at stack overflow, but this should work.
I am using "Godot 3.2.2.stable" and any help would be great.
Upvotes: 0
Views: 3482
Reputation: 3
This is a very simple fix. The node that the script is attached to must have the process mode set to Disabled in godot 4.x but in 3.x it must be set to Process. You can change the setting by selecting the node, scrolling to the bottom in the Inspector under the Node dropdown there should be a dropdown selection that either says Mode or Process Mode.
But if you are using an autoload you shouldn't have to do any of that.
Upvotes: 0
Reputation: 55
Just replace your ready function with following:
func _ready():
pause_mode = Node.PAUSE_MODE_PROCESS
Or you can do the same thing in Node under Inspector Tab.
here is the offical documentation link
Upvotes: 4
Reputation: 1
The problem you are facing is when you pause the tree, even the input process also stops.
FIX: don't make it an auto-load script, attach it to a node and set its pause mode to process.
func _process(delta):
if Input.is_action_pressed("pause"):
get_tree().paused = true
if Input.is_action_pressed("unpause"):
get_tree().paused = false
I hope it will fix the issue. if not here is godot's documentation on this
Upvotes: 0