How can I abort a PIE game without crashing the editor?

Hello! How can I forcefully stop execution of my PIE game without crashing the editor?

The specific use case would be that a designer is using the editor to change data. Something they do is incomplete, so in code we have a nullptr. I want to log the issue and stop executing that thread without bringing down the editor and causing that person to potentially lose work.

E.g.:

 ResultObject MyFunction(SomeData* _myData)
    {
        if (_myData == nullptr)
        {
            UE_LOG(MyCategory, Error, TEXT("Passed in NULL data to MyFunction!"));
            // EXIT GAME HERE e.g. System.Exit(0);
        }
        // Access _myData
        // Do work
        return myResultObject;
    }

Given that we can recompile the game code within the editor, it seems like this could be possible, even if there is not currently such a feature implemented. Another approach might be modifying the editor to support a try/catch around wherever game code is running, and throwing an exception? I know that UE4 does not recommend use of exceptions.

If there is no such way, what is the recommended approach? Unfortunately, writing defensive code that functions in all cases with nullptrs or other bad data is problematic because it means the game keeps running despite bad data, which is not desirable when we have certain types of errors and want to force them to be addressed immediately.

Thanks for your help!

2 Likes

Try and Quit the game, it’ll fall back to the editor: http://api.unrealengine.com/INT/BlueprintAPI/Game/QuitGame/index.html

Unfortunately, this does not immediately stop execution of the thread, so if there is an error after the UKismetSystemLibrary::QuitGame(…) call, the editor still crashes in its entirety.

1 Like

So no answer for this?