Daily Unreal Column #46 - Console Autocomplete
When creating cheat commands, it is not uncommon to use enums or gameplay tags as parameters. Remembering and typing them them is not an easy task. Here is how to implement autocompletion for them.
First thing we need to do is create a subclass of UConsole
engine class. Then we need to replace default console class inside project settings, inside General Settings tab.
Inside the UConsole
subclass we need to override BuildRuntimeAutoCompleteList
function.
Side note: there is an AugmentRuntimeAutoCompleteList
function which is declared with the following comment:
/** Virtual function to allow subclasses of UConsole to add additional commands */
This in theory make it a better candidate for override. However, this function is only being called when BuildRuntimeAutoCompleteList
is called with bForce
parameter set to `true`. Which, in my testing, is never happening. Because of that the only option to append our own commands is by overriding BuildRuntimeAutoCompleteList
itself.
Inside the function, we need to append our commands to the `AutoCompleteList`. See below snippet for an example code.
const FGameplayTag ParentTag = FGameplayTag::RequestGameplayTag("Ability.ActivateFail");
UGameplayTagsManager& GameplayTagManager = UGameplayTagsManager::Get();
FGameplayTagContainer ChildTags = GameplayTagManager.RequestGameplayTagChildren(ParentTag);
for (const FGameplayTag& ChildTag : ChildTags)
{
FAutoCompleteCommand& NewCommand = AutoCompleteList.AddDefaulted_GetRef();
NewCommand.Command = FString::Printf(
TEXT("MyCustomAutocomplete %s"), *ChildTag.ToString());
NewCommand.Desc = "Put your command description here";
}
This is how the autocomplete looks like in game when we open the console and start typing: