bUseAutocorrect

bUseAutocorrect

#Overview

name: bUseAutocorrect

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 8 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of bUseAutocorrect is to control whether autocorrect functionality is enabled for virtual keyboards in Unreal Engine applications, primarily on mobile devices.

This setting variable is primarily used by the Slate module, which is part of Unreal Engine’s UI system. It’s specifically utilized in the input handling and text entry components of the engine.

The value of this variable is set in the InputSettings configuration file (GInputIni). It can be modified through the project settings in the Unreal Engine editor, under the “Input” category.

Several other variables interact with bUseAutocorrect:

  1. ExcludedAutocorrectCultures: An array of culture codes where autocorrect should be disabled.
  2. ExcludedAutocorrectDeviceModels: An array of device models where autocorrect should be disabled (specific to Android).

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

  1. It only affects mobile devices currently.
  2. It’s not applied to password fields for security reasons.
  3. It can be overridden based on the operating system version, culture, or device model (on Android).
  4. The setting can be fine-tuned using the related exclusion lists mentioned above.

Best practices when using this variable include:

  1. Consider the target audience and languages when deciding whether to enable autocorrect.
  2. Test thoroughly on various devices and OS versions to ensure consistent behavior.
  3. Use the exclusion lists to disable autocorrect for specific cultures or devices where it might cause issues.
  4. Remember that this setting affects all non-password text input fields in the application, so consider if a global setting is appropriate for your use case.
  5. Be mindful of the potential impact on user experience, especially for applications requiring precise text input.

#Setting Variables

#References In INI files

Location: <Workspace>/Projects/Lyra/Config/DefaultInput.ini:26, section: [/Script/Engine.InputSettings]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/GameFramework/InputSettings.h:118

Scope (from outer to inner):

file
class        class UInputSettings : public UObject

Source code excerpt:

	/** If enabled, virtual keyboards will have autocorrect enabled. Currently only supported on mobile devices. */
	UPROPERTY(config, EditAnywhere, Category = "Virtual Keyboard (Mobile)")
	uint8 bUseAutocorrect:1;

	/** 
	 * Disables autocorrect for these operating systems, even if autocorrect is enabled. Use the format "[platform] [osversion]"
	 * (e.g., "iOS 11.2" or "Android 6"). More specific versions will disable autocorrect for fewer devices ("iOS 11" will disable
	 * autocorrect for all devices running iOS 11, but "iOS 11.2.2" will not disable autocorrect for devices running 11.2.1).
	 */

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Private/Framework/Application/IPlatformTextField.cpp:8

Scope (from outer to inner):

file
function     bool IPlatformTextField::ShouldUseVirtualKeyboardAutocorrect

Source code excerpt:

bool IPlatformTextField::ShouldUseVirtualKeyboardAutocorrect(TSharedPtr<IVirtualKeyboardEntry> TextEntryWidget)
{
	bool bUseAutocorrect = false;

	if (TextEntryWidget.IsValid() && TextEntryWidget->GetVirtualKeyboardOptions().bEnableAutocorrect)
	{
		switch (TextEntryWidget->GetVirtualKeyboardType())
		{
		case EKeyboardType::Keyboard_Password:
			{
				// Never use autocorrect for password
				bUseAutocorrect = false;
			}
			break;

		case EKeyboardType::Keyboard_Email:
		case EKeyboardType::Keyboard_Web:
		case EKeyboardType::Keyboard_Number:

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Private/Framework/Application/IPlatformTextField.cpp:29

Scope (from outer to inner):

file
function     bool IPlatformTextField::ShouldUseVirtualKeyboardAutocorrect

Source code excerpt:

			{
				// Check to see if autocorrect is turned on in the input settings
				bUseAutocorrect = GConfig->GetBool(TEXT("/Script/Engine.InputSettings"), TEXT("bUseAutocorrect"), bUseAutocorrect, GInputIni);
			}
			break;
		}

		if (bUseAutocorrect)
		{
			static FString PlatformVersion;

			if (PlatformVersion.IsEmpty())
			{
				FString OSVersion;

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Private/Framework/Application/IPlatformTextField.cpp:58

Scope (from outer to inner):

file
function     bool IPlatformTextField::ShouldUseVirtualKeyboardAutocorrect

Source code excerpt:

				if (PlatformVersion.StartsWith(ExcludedVersion))
				{
					bUseAutocorrect = false;
					break;
				}
			}

			// Get the current culture that the game is running in, and check against INI settings to see if autocorrect should be
			// disabled for that culture. E.g., specifying a culture such as "en" in the INI will disable autocorrect for all English 
			// cultures, but specifying "en-CA" will disable autocorrect only for Canadian English.
			if (bUseAutocorrect && FInternationalization::IsAvailable())
			{
				FInternationalization& I18N = FInternationalization::Get();
				TArray<FString> PrioritizedCultureNames = I18N.GetPrioritizedCultureNames(I18N.GetCurrentCulture()->GetName());

				TArray<FString> ExcludedCultures;
				GConfig->GetArray(TEXT("/Script/Engine.InputSettings"), TEXT("ExcludedAutocorrectCultures"), ExcludedCultures, GInputIni);

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Private/Framework/Application/IPlatformTextField.cpp:78

Scope (from outer to inner):

file
function     bool IPlatformTextField::ShouldUseVirtualKeyboardAutocorrect

Source code excerpt:

					if (ExcludedCultures.Contains(CultureName))
					{
						bUseAutocorrect = false;
						break;
					}
				}
			}
		}
	}

	return bUseAutocorrect;
}

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Private/Framework/Text/Android/AndroidPlatformTextField.cpp:130

Scope (from outer to inner):

file
function     bool FAndroidPlatformTextField::ShouldUseAutocorrect

Source code excerpt:

bool FAndroidPlatformTextField::ShouldUseAutocorrect(TSharedPtr<IVirtualKeyboardEntry> TextEntryWidget) const
{
	bool bUseAutocorrect = IPlatformTextField::ShouldUseVirtualKeyboardAutocorrect(TextEntryWidget);

	if (bUseAutocorrect)
	{
		static FString DeviceModel = FAndroidMisc::GetDeviceModel();

		TArray<FString> ExcludedDeviceModels;
		GConfig->GetArray(TEXT("/Script/Engine.InputSettings"), TEXT("ExcludedAutocorrectDeviceModels"), ExcludedDeviceModels, GInputIni);

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Private/Framework/Text/Android/AndroidPlatformTextField.cpp:143

Scope (from outer to inner):

file
function     bool FAndroidPlatformTextField::ShouldUseAutocorrect

Source code excerpt:

			if (DeviceModel.StartsWith(ExcludedModel))
			{
				bUseAutocorrect = false;
				break;
			}
		}
	}

	return bUseAutocorrect;
}

bool FAndroidPlatformTextField::EnableNewKeyboardConfig() const
{
	// read the value from the config file
	static bool bEnableNewKeyboardConfig = false;

#Loc: <Workspace>/Engine/Source/Runtime/Slate/Private/Framework/Text/IOS/IOSPlatformTextField.cpp:10

Scope (from outer to inner):

file
namespace    anonymous
function     void GetKeyboardConfig

Source code excerpt:

	void GetKeyboardConfig(TSharedPtr<IVirtualKeyboardEntry> TextEntryWidget, FKeyboardConfig& KeyboardConfig)
	{
		bool bUseAutocorrect = IPlatformTextField::ShouldUseVirtualKeyboardAutocorrect(TextEntryWidget);

		KeyboardConfig.KeyboardType = UIKeyboardTypeDefault;
		KeyboardConfig.bSecureTextEntry = NO;
		KeyboardConfig.AutocorrectionType = bUseAutocorrect ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo;

		EKeyboardType TargetKeyboardType = TextEntryWidget.IsValid() ? TextEntryWidget->GetVirtualKeyboardType() : Keyboard_Default;
		
		switch (TargetKeyboardType)
		{
		case EKeyboardType::Keyboard_Email: