Reputation: 31
I want to pause game execution for one second every frame. However, the game never resumes, why is that?
I am using the following _process function in the root/world node:
func _process(delta):
get_tree().paused = true
await get_tree().create_timer(1).timeout
get_tree().paused = false
Eventually I want to create some more logic to have the game send and receive information to another non-Godot process, possibly using semaphores and shared memory or some other IPC. So I would not be using any time-based pausing like that. Would appreciate some pointers in that direction as well. Am completely new to Godot.
Upvotes: 3
Views: 1349
Reputation: 51
I don't think the issue is related to the Timer. If you add a print statement immediately after the await line, you'll see that the log gets printed, indicating that the code execution is proceeding past the await.
The real issue seems to be related to how frequently _process is called. The delta parameter in the _process function represents the time elapsed since the last frame, which is usually much smaller than a second (Most games typically run at 60 FPS). As your program is paused and then resumed frequently by the rapid succession of _process calls, it appears as if it's constantly in a paused state.
Upvotes: 0
Reputation: 40315
the game never resumes, why is that?
The expression get_tree().create_timer(1)
will create a SceneTreeTimer
, which will not execute while the game is paused.
If you want a timer that will run even when the game is paused, use a Timer
(the Node
) which you can set to run even while the game is paused by setting its process_mode
.
I also want to point out that you can create Thread
s in Godot, and have them sleep with OS.delay_msec
.
Eventually I want to create some more logic to have the game send and receive information to another non-Godot process, possibly using semaphores and shared memory or some other IPC
There aren't many options for inter-process communication with Godot. In part because games don't use them often, and in part because it is hard - if not impossible - to implement a portable solution for the platforms that Godot supports.
So, Godot does not have built-in support for named semaphores, nor named pipes, nor shared memory. Being mindful of the target platform, you could use C# or C++ with GDExtension to get access to such features.
Limiting yourself to what Godot can do out of the box, you could:
OS.execute
passing data as command line arguments. The calling thread in Godot will block during the execution, so it can get the standard output from the other program back. And the other program could do whatever means of communication you want if necessary.TCPServer
or UDPServer
(you might want to check and close connection that are not from localhost). Alternatively, you can have Godot connect to a server with StreamPeerTCP
or PacketPeerUDP
. There is also HTTPClient
if what you need to communicate on the other side is a web server.Upvotes: 0