Skip to content

Instantly share code, notes, and snippets.

@gamerxl
Last active January 15, 2023 17:26
Show Gist options
  • Save gamerxl/14deba4b86125d80f1c40338ea9fbf99 to your computer and use it in GitHub Desktop.
Save gamerxl/14deba4b86125d80f1c40338ea9fbf99 to your computer and use it in GitHub Desktop.
Register a custom console command from c++ in unreal engine.
// Example for registration of a custom console command.
// Use a custom game instance and override method Init from UGameInstance.
void UCustomGameInstance::Init()
{
Super::Init();
// Register a custom command to load a map.
if (!IConsoleManager::Get().IsNameRegistered(TEXT("LoadMap")))
{
// Remove existing command.
IConsoleObject* LoadMapConsoleObject = IConsoleManager::Get().FindConsoleObject(TEXT("LoadMap"));
if (LoadMapConsoleObject != nullptr)
{
IConsoleManager::Get().UnregisterConsoleObject(LoadMapConsoleObject);
}
IConsoleManager::Get().RegisterConsoleCommand(
TEXT("LoadMap"),
TEXT("Empty help / description"),
FConsoleCommandDelegate::CreateUObject(this, &UCustomGameInstance::LoadMap));
}
}
}
void UCustomGameInstance::LoadMap()
{
// Do something e.g. load a map.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment