Last active
December 4, 2024 10:46
-
-
Save gamerxl/14deba4b86125d80f1c40338ea9fbf99 to your computer and use it in GitHub Desktop.
Register a custom console command from c++ in unreal engine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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