DetectionByAffiliation

DetectionByAffiliation

#Overview

name: DetectionByAffiliation

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

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of DetectionByAffiliation is to control which AI-controlled entities can detect or sense other entities based on their affiliation or team alignment. This variable is used in the AI perception system of Unreal Engine 5, specifically for hearing, sight, and touch senses.

DetectionByAffiliation is utilized by the AI Module in Unreal Engine 5, particularly within the perception system. It is referenced in the configuration classes for hearing (UAISenseConfig_Hearing), sight (UAISenseConfig_Sight), and touch (UAISenseConfig_Touch) senses.

The value of this variable is set through the Unreal Engine editor, as indicated by the UPROPERTY macro with the “EditAnywhere” and “config” specifiers. This allows developers to configure the detection settings for each sense type in the editor or through configuration files.

DetectionByAffiliation interacts with the FAISenseAffiliationFilter struct, which is used to filter detections based on affiliation. The GetAsFlags() method of this struct is called to convert the filter settings into a set of flags used by the perception system.

Developers should be aware that this variable affects how AI-controlled entities perceive other entities in the game world. Proper configuration of this variable is crucial for creating realistic and balanced AI behavior.

Best practices when using this variable include:

  1. Carefully consider the gameplay implications of detection settings for each sense type.
  2. Ensure consistency across different AI characters that should have similar detection capabilities.
  3. Use this variable in conjunction with other perception settings (e.g., range, angle) to create nuanced AI behavior.
  4. Test different configurations to find the right balance for your game’s AI requirements.
  5. Document the chosen settings and their impact on gameplay for team reference.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseGame.ini:198, section: [/Script/AIModule.AISenseConfig_Hearing]

Location: <Workspace>/Engine/Config/BaseGame.ini:205, section: [/Script/AIModule.AISenseConfig_Sight]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Classes/Perception/AISenseConfig_Hearing.h:35

Scope (from outer to inner):

file
class        class UAISenseConfig_Hearing : public UAISenseConfig

Source code excerpt:


	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Sense", config)
	FAISenseAffiliationFilter DetectionByAffiliation;

	AIMODULE_API virtual TSubclassOf<UAISense> GetSenseImplementation() const override;

#if WITH_GAMEPLAY_DEBUGGER_MENU
	AIMODULE_API virtual void DescribeSelfToGameplayDebugger(const UAIPerceptionComponent* PerceptionComponent, FGameplayDebuggerCategory* DebuggerCategory) const override;
#endif // WITH_GAMEPLAY_DEBUGGER_MENU

#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Classes/Perception/AISenseConfig_Sight.h:38

Scope (from outer to inner):

file
class        class UAISenseConfig_Sight : public UAISenseConfig

Source code excerpt:

	/** */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Sense", config)
	FAISenseAffiliationFilter DetectionByAffiliation;

	/** If not an InvalidRange (which is the default), we will always be able to see the target that has already been seen if they are within this range of their last seen location. */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Sense", config, meta = (Units="Centimeters"))
	float AutoSuccessRangeFromLastSeenLocation;

	/** Point of view move back distance for cone calculation. In conjunction with near clipping distance, this will act as a close by awareness and peripheral vision. */

#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Classes/Perception/AISenseConfig_Touch.h:16

Scope (from outer to inner):

file
class        class UAISenseConfig_Touch : public UAISenseConfig

Source code excerpt:


	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Sense", config)
	FAISenseAffiliationFilter DetectionByAffiliation = {true, true, true};
	
	AIMODULE_API virtual TSubclassOf<UAISense> GetSenseImplementation() const override;
};

#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Private/Perception/AISense_Hearing.cpp:39

Scope (from outer to inner):

file
function     UAISense_Hearing::FDigestedHearingProperties::FDigestedHearingProperties

Source code excerpt:

{
	HearingRangeSq = FMath::Square(SenseConfig.HearingRange);
	AffiliationFlags = SenseConfig.DetectionByAffiliation.GetAsFlags();
}

UAISense_Hearing::FDigestedHearingProperties::FDigestedHearingProperties()
	: HearingRangeSq(-1.f)
{
	AffiliationFlags = FAISenseAffiliationFilter::DetectAllFlags();

#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Private/Perception/AISense_Sight.cpp:117

Scope (from outer to inner):

file
function     UAISense_Sight::FDigestedSightProperties::FDigestedSightProperties

Source code excerpt:

	NearClippingRadiusSq = FMath::Square(SenseConfig.NearClippingRadius);
	PeripheralVisionAngleCos = FMath::Cos(FMath::Clamp(FMath::DegreesToRadians(SenseConfig.PeripheralVisionAngleDegrees), 0.f, PI));
	AffiliationFlags = SenseConfig.DetectionByAffiliation.GetAsFlags();
	// keep the special value of FAISystem::InvalidRange (-1.f) if it's set.
	AutoSuccessRangeSqFromLastSeenLocation = (SenseConfig.AutoSuccessRangeFromLastSeenLocation == FAISystem::InvalidRange) ? FAISystem::InvalidRange : FMath::Square(SenseConfig.AutoSuccessRangeFromLastSeenLocation);
}

UAISense_Sight::FDigestedSightProperties::FDigestedSightProperties()
	: PeripheralVisionAngleCos(0.f), SightRadiusSq(-1.f), AutoSuccessRangeSqFromLastSeenLocation(FAISystem::InvalidRange), LoseSightRadiusSq(-1.f), PointOfViewBackwardOffset(0.0f), NearClippingRadiusSq(0.0f)

#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Private/Perception/AISense_Touch.cpp:35

Scope (from outer to inner):

file
function     UAISense_Touch::FDigestedTouchProperties::FDigestedTouchProperties

Source code excerpt:

UAISense_Touch::FDigestedTouchProperties::FDigestedTouchProperties(const UAISenseConfig_Touch& SenseConfig)
{
	AffiliationFlags = SenseConfig.DetectionByAffiliation.GetAsFlags();
}

UAISense_Touch::FDigestedTouchProperties::FDigestedTouchProperties()
{
	AffiliationFlags = FAISenseAffiliationFilter::DetectAllFlags();
}