+2 votes


I have a bit on unusual problem.
I'm using GODOT 4.0 for training AI using reinforcement learning on full game frames. To do this I'm sending "screenshot" of the game to my AI software every frame (using gRPC).

This is how the processing function looks like:

public override void _PhysicsProcess(double delta)
    // Do capturing only if AI is listening
    if (ChannelController.GetChannelsCount() > 0)
        Task.Run(() =>
            // Capture game frame as JPG
            var img = GetViewport().GetTexture().GetImage().SaveJpgToBuffer();
            var fd = new FrameData();
            // Convert JPG to ByteString for gRPC compatibility
            fd.VideoData = Google.Protobuf.ByteString.CopyFrom(img);
            // Send captured frame to AI

This function works fine and allows me to capture and process game frames with great performance. Only issue is - it works only when game window is visible.

The moment I minimize the window or switch to different workspace, game is still running, but update of viewport stops, so the result is, that I'm sending to the AI same frame over and over again.
If I restore the game window, everything goes back to normal.

So, my question:
Is it possible to force normal rendering and viewport updates even if game window is minimized?
Allowing it to run minimized, or even without window at all, would be a great help for my project.

Godot version 4.0 beta3
in Engine by (203 points)

1 Answer

0 votes

Found an answer or at least workaround. I don't know if this is the proper way of doing it, but this line of code inside _PhysicsProcess function make rendering happen on minimized game:

if (RenderingServer.HasChanged()) RenderingServer.ForceDraw();

If anyone knows better, more elegant solution, please let me know.

by (203 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.