INTRODUCTION
While building my Unreal Engine 5 gameplay systems, I encountered an issue where enemies could accidentally damage actors from the same faction.
To solve this, I implemented a team-based combat system using Unreal Engine’s built-in FGenericTeamId interface. This allowed AI characters to recognize friendly and hostile targets dynamically during combat.
SYSTEM GOAL
The goal of the system was:
Prevent friendly fire
Allow enemy factions
Support future ally systems
Keep combat logic scalable
Handle AI attitude checks in C++
IMPLEMENTATION
Each enemy character was assigned a team ID using FGenericTeamId.
The team ID is returned through the IGenericTeamAgentInterface.
CODE BLOCK
virtual FGenericTeamId GetGenericTeamId() const override
{
return FGenericTeamId(EnemyTeamID);
}
ATTITUDE CHECK
Before applying damage, the system compares the attacker and target teams.
SECOND CODE BLOCK
ETeamAttitude::Type Attitude =
FGenericTeamId::GetAttitude(AttackerTeam, TargetTeam);
if (Attitude != ETeamAttitude::Friendly)
{
ApplyDamage();
}
RESULT
This system made enemy combat much more reliable and scalable.
It also prepares the project for:
• allied AI
• companion systems
• faction gameplay
• PvE combat logic
• future multiplayer support
WHAT I LEARNED
Through this system, I improved my understanding of:
• Unreal Engine AI systems
• C++ gameplay architecture
• interface-based programming
• scalable combat logic
• clean gameplay programming practices
