Can I restart the UE editor after it crashes

I have placed my Unreal Engine editor on a server to perform my preset tasks, but I cannot guarantee that the editor will always run normally. Can I restart the UE editor after it crashes? I’m not sure where in the C++ code I should write this. Please help me.

Hey @Anonymous_1eb9dd08de3fec066ad189e21dead984!

To help get the ball rolling and for clarification, are you asking how to have the editor automatically reopen itself if it crashes?

Any additional specifics you provide will go a long way in solving your problem!

I’d like to know this as well but I’m not yet at the stage to try it.

Claude AI gave this answer and you could use it or ChatGPT to try and get more granular detail:

To handle potential crashes and automatically restart the Unreal Engine editor on a server, you’ll need to implement a watchdog system outside of the Unreal Engine codebase itself. This is because once the editor crashes, the C++ code within the engine won’t be running anymore.

Here’s a high-level approach you could take:

  1. Create a separate watchdog process that monitors the Unreal Engine editor.
  2. If the watchdog detects that the editor has crashed or stopped responding, it can restart the editor.

Here’s a basic example of how you might implement this in C++:

#include <iostream>
#include <chrono>
#include <thread>
#include <cstdlib>
#include <process.h>
#include <windows.h>

bool isProcessRunning(const char* processName) {
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hSnapshot == INVALID_HANDLE_VALUE) {
        return false;
    }

    PROCESSENTRY32 pe32;
    pe32.dwSize = sizeof(PROCESSENTRY32);

    if (Process32First(hSnapshot, &pe32)) {
        do {
            if (strcmp(pe32.szExeFile, processName) == 0) {
                CloseHandle(hSnapshot);
                return true;
            }
        } while (Process32Next(hSnapshot, &pe32));
    }

    CloseHandle(hSnapshot);
    return false;
}

void startUnrealEditor() {
    // Replace with the actual path to your Unreal Editor executable
    system("start \"\" \"C:\\Path\\To\\UnrealEditor.exe\"");
}

int main() {
    const char* editorProcessName = "UnrealEditor.exe";
    
    while (true) {
        if (!isProcessRunning(editorProcessName)) {
            std::cout << "Unreal Editor is not running. Restarting..." << std::endl;
            startUnrealEditor();
        }
        
        // Wait for 60 seconds before checking again
        std::this_thread::sleep_for(std::chrono::seconds(60));
    }

    return 0;
}

This script does the following:

  1. It continuously checks if the Unreal Editor process is running.
  2. If the process is not found, it attempts to restart the editor.
  3. It waits for 60 seconds before checking again.

To use this script:

  1. Compile it as a separate executable.
  2. Run this executable on your server alongside the Unreal Engine editor.
  3. Make sure to replace the path in the startUnrealEditor() function with the actual path to your Unreal Editor executable.

Keep in mind that this is a basic implementation and you might want to add more robust error handling, logging, and perhaps a way to gracefully shut down the watchdog process.

Also, note that frequently restarting the editor after crashes might indicate underlying issues that should be addressed. It’s important to investigate the root causes of any crashes and resolve them if possible.


Maybe this is useful… let us know how you go

Yes, that’s correct. I would like the Unreal Engine editor to automatically restart itself if it crashes while running on the server. My goal is to ensure that the editor can recover and continue executing the preset tasks without manual intervention. If there is a way to implement this in C++, could you guide me on where to write the code? Any advice or recommendations would be greatly appreciated.

(post deleted by author)

Thank you! I’ll try to implement this.