Download

Console Commands from C++

For debug reasons I’m trying to hook in some console commands to hot keys. I’ve found numerous threads both here and on stackoverflow talking about executing console commands in code, but none of the techniques seem to work any more. All the posts were from older Unreal versions, though, so I’m unsure if either I’m doing something wrong or if the way to do it has been changed.

The code I’m using is something this:


FString command = "stat SceneRendering";
GetWorld()->Exec(GetWorld(), *command);

Any suggestions as to what I might be doing wrong?

We use this. Get ref to player controller then:


_playerController->ConsoleCommand("quit");

GetWorld()->Exec(GetWorld(), *command) works for me except inside a GameMode, it seems. Perhaps APlayerController::ConsoleCommand() has some additional magic.

Thanks! Yeah, the playercontroller one works great.