Function to advance to next frame

Hey guys, I am trying to use UE to do reinforcement learning and would like to build up a function similar to the step function inside OpenAI’s gym.
There’s a button on the top part of the editor, called advance to next frame, which could achieve what I want. Snipaste_2024-07-31_10-35-36
However, after searching, this button can’t be called in blueprint or c++. Is there any way to call this function? Appreciate any suggestions. Thank you in advance.

UI_COMMAND(SingleFrameAdvance, “Skip”, “Advances a single frame”, EUserInterfaceActionType::Button, FInputChord());

DebuggerCommands.cpp
in
\Engine\Source\Editor\UnrealEd\Private\Kismet2

Most likely this portion of code:



void FInternalPlayWorldCommandCallbacks::SingleFrameAdvance_Clicked()
{
	if (IsStoppedAtBreakpoint_InEngineMode())
	{
		return;
	}

	// We want to function just like Single stepping where we will stop at a breakpoint if one is encountered but we also want to stop after 1 tick if a breakpoint is not encountered.
	FKismetDebugUtilities::RequestSingleStepIn();
	if (HasPlayWorld())
	{
		GUnrealEd->PlayWorld->bDebugFrameStepExecution = true;
		LeaveDebuggingMode();
		GUnrealEd->PlaySessionSingleStepped();
	}
}

Thank you for your quick and excellent reply.

Can I ask what library you have included in your code? When I try to use them in my code, FKismetDebugUtilities and GUnrealEd cannot be recognized.

I’m still dissecting the unreal engine code to get it running from a static lib :wink:
So far it does pause the game but still doesn’t single step.

Really thrilled to hear that. Hope you can solve it. Thank you!

It was pretty tough. Had to dig through a lot of source code to get the needed functions step by step with namespaces etc. But it works :slight_smile:

Remember it uses UnrealEd so if you need this as a tool for a game you are publishing you would need to export it to a plugin that is only for uncooked mode otherwise it will cause problems with packing.

edit: re-upload: forgot to add the function to public:

AdvanceFunctionLibrary.cpp (1.1 KB)
AdvanceFunctionLibrary.h (461 Bytes)

video of it in action

It’s a static library so just include

#include "AdvanceFunctionLibrary.h"

and then you can call

UAdvanceFunctionLibrary::StepAdvanceFrame();
1 Like

Awsome! Thank you for your contribution!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.