Believe it or not, you just alleviated an hour of headaches with this one comment. For anyone else who needs clarification, the top-level node has to be a CanvasLayer, with the Control node as a parent of it. Not the other way around, like I managed to do.
@@Yaya-toure-A Put static overlay UI Control nodes (PauseMenu node in this video) into a CanvasLayer parent, not as a child of the Camera2D. Or just change the type of the root node of your PauseMenu to CanvasLayer. That way, when you insert it into another scene (e.g., "main" in this video), it will render on top of everything else and disregard the camera's transformation.
i recommend using "get_tree().paused = true or false" to pause the game, since using engine.scale = 0 still records inputs from your keyboard, so you can jump or shoot in the menu, and engine.scale = 0 bugged my rigidbody3d for some reason. try using this: func pause(state): if state: Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) menu.hide() get_tree().paused = false else: Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) get_tree().paused = true menu.show() but you have to allow your menu node to work when the game is paused, every node has a process tab on the inspector menu, change the process mode to "when paused"
I was confused in your example for a sec why true and false were seemingly swapped around, before realizing they're not! Huge mistake on my part, but for anyone else who gets confused, like I did, in the original script in the video, the 1 and 0 are for the timescale, and the're more like if the game time is moving or not. So in the video, a timescale of 0 means the game isn't moving, whereas in this example, if the game is in a paused state, you'd say the paused state is true (which can also be represented as 1) in programming, typically 0 is false, and 1 is true. so in my mind, I was confused why the numbers got flipped. This was very unintuitive to me until I worked it out logically. so to recap, in the video, they're setting the time scale (essentially the speed the game is moving at) to on or off (moving or not moving; paused or unpaused) which is why it uses a timescale of 0 or 1 (off or on) in this example, you're using an inbuilt pause variable, so it seems flipped, but it's really not; the question is changing from "should the game be moving" to "should the game be paused", which sound the same, but would have flipped answers to mean the same thing. if the game is NOT moving, then it IS paused. sorry for rambling, just wanted to share in case anyone else was confused.
thank you for the advice!! is there a way to make it so that you can still use the escape key to unpause, whilst still not being able to accept other keyboard inputs?
@@chloe.v took me a minute to figure this out too. You have to set the process for the pause menu to "always" (so it can still read inputs when the game is paused) and it can't have any parents upstream that conflict with that. so for example, if you put your pause menu as a child of the player, that wouldn't work, because you want the player to pause when the menu opens, and the pause menu won't work if it's a child of a pausable entitiy and also needs to be able to read inputs when paused. my solution is to either put the pause menu as a child of the level, have the (root) set to always in the process tab, and then have a child of the level that's called "pausable" that everything that should be able to be paused gets child-ed to. then I came up with a better solution: make a new parent for the player entity, and set the pause menu and player as children of it. then set that parent to always and the player process set to pausable. The biggest thing to remember is just that anything upstream of the pause menu in the parenting tree can't be pausable, or it'll break the pause menu's ability to unpause (seeing as it'll be paused and then can't take inputs 😵💫)
This is awesome! Subscribed. Could you please make an Options menu as well? Also would be nice to see how to switch scenes with a loading screen in a 3D game.
This shows exactly what I needed (even the blur, funny enough) but I was hoping you would explain what it was you were actually doing. I understand godot very minorly but enough to understand everything up until the blur portion of the video. All that code you wrote to implement the blur went right over my head. Wish it was explained :/
Yes, there are a few options: - Use @export annotation instead, and drag'n'drop the relevant node into it. - Use an absolute path instead (e.g. $"/root/MyMainScene/MyPauseMenu"). - Use a global event bus, i.e. a signal in an autoload script, which will be emitted when you click the button from wherever your code handles input, and connected to a function that toggles the pause menu's visiblity.
hello. I followed your instructions, and it did help me. however, there's a problem that I encountered when I tried to open the pause menu; the buttons shows behind the player. I also tried putting it at the very bottom and at the very top of the layer but nothing happens. can you help me?
On your pause menu node, go to Inspector > Ordering > and change the Z Index to a number higher than the Ordering on your player node. Consider this as a Z axis where anything > 0 is approaching you and anything < 0 is going further away from you
It didn't like me just using show()/hide() or getting rid of self (it said those functions/identifiers weren't declared in the current scope). Maybe it's because the root of my pause menu is a canvas layer instead of a node? Or might be because I made my pause_menu.tscn an autoload so I don't have to put in in every scene? Don't know lol, but self.visible seems to work for me
Found my issue lol, when I changed the root to a canvas layer I had forgotten to also change extends Node to extends CanvasLayer, so now show()/hide() work as expected
what are my options for using functions such as `_unhandled_input(event)` to handle all of this? will that get affected by time scale? or similar things?
I've enabled viewport following and the pause menu is now a child of the camera node, but *still doesn't follow the player view.* Is there something I'm just not checking?
I had the same issue when my background was not evenly filled (ie the background had empty spaces between the texture I wanted to blur). Putting another ColorRect behind with full black solved.. hope that helps you too!
damn have a issue that in my menu works but blur effect does not appear , even so i checked other tutorials and they have everything the same. What i should do? Where in tree i should put pause menu on level or on camera of my character?
In the material section of the color rect you have added shader there should be an option called shader parameters click on it and set value of 3 if you have missed it if this didn't help maybe redo the tutorial, my problem was same 😊😊😊😊
does the pause script have to be in the root node? mainly wondering cuz i do wanna disable the pause function if my player is reading a news article in game [and since escape is used to exit article i dont want it to bring up the pause function]
Are you using Input.MOUSE_MODE_CAPTURED? If yes, here's what a did: In process Delta when you press pause button you set mouse mode to visible Down in the Delta func u write If not paused Paused = false. It works but quite weird.
SUBBED AND LIKED! I have been struggling to get my pause menu working in my platform game for 2 days but I got it working thanks to you and some code and node restructuring. I also got your shader working but had to save it as a scene, make it hidden and show it when paused and hide it when un-paused. I also corrected your code for pausing. You have to also make process mode in the Inspector 'pausable' on any any node you want to pause and change it to 'when paused' on the pause menu node. See my code below: @onready var bg_blur = %"Shader bg blur" @onready var pause_menu = %"Pause Menu" var paused = true func _ready(): pass # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): if Input.is_action_just_pressed("menu"): #You might have called menu something else. #Change #it. pauseMenu() func pauseMenu(): if paused: print ("Paused", paused) Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) pause_menu.show() bg_blur.show() get_tree().paused = true else: print ("UN-Paused" , paused) Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) pause_menu.hide() bg_blur.hide() get_tree().paused = false paused = !paused Loving this coding me like. Might do a dev blog on YT