AIControllerClassName

AIControllerClassName

#Overview

name: AIControllerClassName

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

#Summary

#Usage in the C++ source code

The purpose of AIControllerClassName is to specify the default AI controller class for pawns in Unreal Engine 5. This setting variable is crucial for the AI system within the engine.

The AIControllerClassName variable is primarily used by the Engine and AI modules of Unreal Engine 5. It is referenced in various parts of the engine, including the core UObject utilities, replication system tests, and the Pawn class.

The value of this variable is typically set in the engine configuration files. As seen in the code excerpts, it is often set to “/Script/AIModule.AIController” using the GConfig system. This setting can be modified in the project settings or through code using GConfig->SetString().

This variable interacts closely with the AIControllerClass property of the Pawn class. The Pawn class uses the AIControllerClassName to determine and set its AIControllerClass during initialization.

Developers should be aware that:

  1. This variable determines the default AI controller for all pawns in the game.
  2. Changing this value affects the entire project and may have wide-ranging implications for AI behavior.
  3. The specified class must be a valid subclass of AIController.

Best practices when using this variable include:

  1. Ensure that the specified class exists and is correctly implemented before changing this value.
  2. Use project settings to modify this value when possible, rather than hard-coding it, to maintain flexibility.
  3. Be cautious when changing this value in runtime, as it may affect existing pawns and AI behavior.
  4. When creating custom AI controllers, consider whether they should be set as the default or used more selectively.
  5. Always validate that the path to the AI controller class is correct and the class is loadable, especially when working with plugins or modular projects.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:135, section: [/Script/Engine.Engine]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Developer/LowLevelTestsRunner/Private/TestCommon/CoreUObjectUtilities.cpp:64

Scope (from outer to inner):

file
function     void InitCoreUObject

Source code excerpt:


#if WITH_ENGINE && UE_LLT_WITH_MOCK_ENGINE_DEFAULTS
		GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("AIControllerClassName"), TEXT("/Script/AIModule.AIController"), GEngineIni);
		GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("DefaultMaterialName"), TEXT("/Engine/Transient.MockDefaultMaterial"), GEngineIni);
		GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("DefaultLightFunctionMaterialName"), TEXT("/Engine/Transient.MockDefaultMaterial"), GEngineIni);
		GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("DefaultDeferredDecalMaterialName"), TEXT("/Engine/Transient.MockDefaultMaterial"), GEngineIni);
		GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("DefaultPostProcessMaterialName"), TEXT("/Engine/Transient.MockDefaultMaterial"), GEngineIni);
#endif // WITH_ENGINE && UE_LLT_WITH_MOCK_ENGINE_DEFAULTS

#Loc: <Workspace>/Engine/Source/Programs/ReplicationSystemTest/Private/ReplicationSystemTest.cpp:164

Scope (from outer to inner):

file
function     static void PreInit

Source code excerpt:

	// Config overrides
	GConfig->SetInt(TEXT("/Script/Engine.GarbageCollectionSettings"), TEXT("gc.MaxObjectsNotConsideredByGC"), 0, GEngineIni);
	GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("AIControllerClassName"), TEXT("/Script/AIModule.AIController"), GEngineIni);
	GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("DefaultMaterialName"), TEXT("/Engine/Transient.MockDefaultMaterial"), GEngineIni);
	GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("DefaultLightFunctionMaterialName"), TEXT("/Engine/Transient.MockDefaultMaterial"), GEngineIni);
	GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("DefaultDeferredDecalMaterialName"), TEXT("/Engine/Transient.MockDefaultMaterial"), GEngineIni);
	GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("DefaultPostProcessMaterialName"), TEXT("/Engine/Transient.MockDefaultMaterial"), GEngineIni);

	// Console commands

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/Engine.h:823

Scope (from outer to inner):

file
class        class UEngine : public UObject , public FExec

Source code excerpt:

	/** Sets the class to be used as the default AIController class for pawns. */
	UPROPERTY(globalconfig, noclear, meta = (MetaClass = "/Script/AIModule.AIController", DisplayName = "Default AIController class for all Pawns"))
	FSoftClassPath AIControllerClassName;

	UPROPERTY()
	TSubclassOf<class UPhysicsCollisionHandler>	PhysicsCollisionHandlerClass;

	/** Sets the PhysicsCollisionHandler class to use by default, which can be overridden to change game-specific behavior when objects collide using physics. */
	UPROPERTY(globalconfig, noclear, EditAnywhere, Category=DefaultClasses, meta=(MetaClass="/Script/Engine.PhysicsCollisionHandler", DisplayName="Physics Collision Handler Class", ConfigRestartRequired=true), AdvancedDisplay)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Pawn.cpp:57

Scope (from outer to inner):

file
function     APawn::APawn

Source code excerpt:

#endif

		FString AIControllerClassName = GetDefault<UEngine>()->AIControllerClassName.ToString();
		check(FPackageName::IsValidObjectPath(AIControllerClassName));
		// resolve the name to a UClass
		AIControllerClass = FindObject<UClass>(nullptr, *AIControllerClassName);

		// if we failed to resolve, and plugins are expected to be loaded, proceed with loading it
		if (AIControllerClass == nullptr && bLoadPluginClass)
		{
			// WARNING: This line is why the AISupport plugin has to load the AIModule before UObject initialization, otherwise this load fails and CDOs are corrupt in the editor
			AIControllerClass = LoadClass<AController>(nullptr, *AIControllerClassName, nullptr, LOAD_None, nullptr);
		}
	}
	else
	{
		AIControllerClass = ((APawn*)APawn::StaticClass()->GetDefaultObject())->AIControllerClass;
	}