UserDefinedChords

UserDefinedChords

#Overview

name: UserDefinedChords

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of UserDefinedChords is to manage and store user-defined keyboard shortcuts or input bindings in Unreal Engine 5. It allows users to customize the input commands for various actions within the engine or game.

UserDefinedChords is primarily used in the Slate module, which is part of Unreal Engine’s UI framework. Specifically, it is utilized by the InputBindingManager class to handle custom key bindings.

The value of this variable is set when the engine loads the user-defined chords from configuration files. This happens in the FUserDefinedChords::LoadChords function, which attempts to load the chords from the GEditorKeyBindingsIni file.

UserDefinedChords interacts with other variables and systems, such as:

  1. GConfig: Used to read and write chord configurations.
  2. FInputChord: Represents individual input chord data.
  3. FUICommandInfo: Stores command information associated with chords.

Developers should be aware of the following when using this variable:

  1. It supports backward compatibility for older configurations named “UserDefinedGestures”.
  2. The chords are stored in a JSON array format in the configuration file.
  3. There’s a separate ProjectDefinedChords for project-specific bindings.

Best practices when using this variable include:

  1. Always check if UserDefinedChords is valid before using it.
  2. Use the provided methods (GetUserDefinedChord, SetUserDefinedChords) to interact with the chords instead of accessing them directly.
  3. Remember to call SaveChords() after making changes to persist the modifications.
  4. Be mindful of potential conflicts with default keybindings and provide a way for users to reset to defaults if needed.
  5. Consider using the OnUserDefinedChordChanged delegate to react to changes in user-defined chords throughout your application.

#Setting Variables

#References In INI files

Location: <Workspace>/Projects/Lyra/Config/DefaultEditorKeyBindings.ini:2, section: [UserDefinedChords]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Private/Framework/Commands/InputBindingManager.cpp:145

Scope (from outer to inner):

file
function     void FUserDefinedChords::LoadChords

Source code excerpt:

		// First, try and load the chords from their new location in the ini file
		// Failing that, try and load them from the older txt file
		bool bFoundChords = (GConfig->GetArray(TEXT("UserDefinedChords"), TEXT("UserDefinedChords"), ChordJsonArray, GEditorKeyBindingsIni) > 0);
		if (!bFoundChords)
		{
			// Backwards compat for when it was named gestures
			bFoundChords = (GConfig->GetArray(TEXT("UserDefinedGestures"), TEXT("UserDefinedGestures"), ChordJsonArray, GEditorKeyBindingsIni) > 0);
		}

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Private/Framework/Commands/InputBindingManager.cpp:244

Scope (from outer to inner):

file
function     void FUserDefinedChords::SaveChords

Source code excerpt:

		}

		GConfig->SetArray(TEXT("UserDefinedChords"), TEXT("UserDefinedChords"), ChordJsonArray, GEditorKeyBindingsIni);

		// Clean up old keys (if they still exist)
		GConfig->RemoveKey(TEXT("UserDefinedGestures"), TEXT("UserDefinedGestures"), GEditorKeyBindingsIni);
		GConfig->RemoveKey(TEXT("UserDefinedChords"), TEXT("Content"), GEditorKeyBindingsIni);
		GConfig->RemoveKey(TEXT("UserDefinedChords"), TEXT("Content"), GEditorKeyBindingsIni);
	}
}

bool FUserDefinedChords::GetUserDefinedChord( const FName BindingContext, const FName CommandName, const EMultipleKeyBindingIndex ChordIndex, FInputChord& OutUserDefinedChord ) const
{
	bool bResult = false;

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Private/Framework/Commands/InputBindingManager.cpp:321

Scope (from outer to inner):

file
function     bool FInputBindingManager::GetUserDefinedChord

Source code excerpt:

bool FInputBindingManager::GetUserDefinedChord( const FName InBindingContext, const FName InCommandName, const EMultipleKeyBindingIndex InChordIndex, FInputChord& OutUserDefinedChord )
{
	if( !UserDefinedChords.IsValid() )
	{
		UserDefinedChords = MakeShareable( new FUserDefinedChords );
		UserDefinedChords->LoadChords();
	}

	return UserDefinedChords->GetUserDefinedChord( InBindingContext, InCommandName, InChordIndex, OutUserDefinedChord );
}

void FInputBindingManager::CheckForDuplicateDefaultChords( const FBindingContext& InBindingContext, TSharedPtr<FUICommandInfo> InCommandInfo ) const
{
	const bool bCheckDefault = true;
	for (uint32 i = 0; i < static_cast<uint8>(EMultipleKeyBindingIndex::NumChords); ++i)

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Private/Framework/Commands/InputBindingManager.cpp:394

Scope (from outer to inner):

file
function     void FInputBindingManager::NotifyActiveChordChanged

Source code excerpt:


	// The user defined chords should have already been created
	check( UserDefinedChords.IsValid() );

	UserDefinedChords->SetUserDefinedChords( CommandInfo );

	// Broadcast the chord event when a new one is added
	OnUserDefinedChordChanged.Broadcast(CommandInfo);
}

void FInputBindingManager::SaveInputBindings()
{
	if( UserDefinedChords.IsValid() )
	{
		UserDefinedChords->SaveChords();
	}
}

void FInputBindingManager::RemoveUserDefinedChords()
{
	if( UserDefinedChords.IsValid() )
	{
		UserDefinedChords->RemoveAll();
		UserDefinedChords->SaveChords();
	}
}

void FInputBindingManager::GetCommandInfosFromContext( const FName InBindingContext, TArray< TSharedPtr<FUICommandInfo> >& OutCommandInfos ) const
{
	ContextMap.FindRef( InBindingContext ).CommandInfoMap.GenerateValueArray( OutCommandInfos );

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Public/Framework/Commands/InputBindingManager.h:279

Scope (from outer to inner):

file
class        class FInputBindingManager

Source code excerpt:


	/** User defined chord overrides for commands */
	TSharedPtr< class FUserDefinedChords > UserDefinedChords;

	/** Project defined chord overrides for commands */
	TSharedPtr< class FUserDefinedChords > ProjectDefinedChords;

	/** Delegate called when a user-defined chord is edited */
	FOnUserDefinedChordChanged OnUserDefinedChordChanged;