C++ Team Character id configured in BP

Hi,

trying to create c++ class which will server as generic team parent character class for multiple enemy NPC “factions”.

Here is code:

UCLASS()
class RTS_API ATeamCharacter : public ACharacter, public IGenericTeamAgentInterface
{
GENERATED_BODY()

public:
UPROPERTY(EditAnywhere)
FGenericTeamId TeamId;

virtual FGenericTeamId GetGenericTeamId() const override
{ 
	UE_LOG(LogTemp, Warning, TEXT("%d"), TeamId.GetId());
	return TeamId;
}

};

Then I’ve created 1 BP character with this C++ class as parent. This will be main class with shared logic and functions. And then from this BP are inheriting two BPs, RedChar and BlueChar in which I’ve set TeamID as UPROPERTY to different values. Configured sense source on both of them and created shared AiController with sight perception, did tick to sense only enemies, however if I for example place two BlueChar in map they will sense each other even thought I only want to sense enemies.

So my question is how could they sense each other ? They should have same TeamID for sure.
Also it seems that GetGenericTeamId method is not even called since no output has been printed.

AAIController also implements IGenericTeamAgentInterface. I think you need to use SetGenericTeamId to make the Controller’s TeamId match the pawn / just use the controller’s team

Tried that however it’s not working neither. Created two controllers, used them for two separate BPs and still they can not sense each other as enemy.

ARedAIController::ARedAIController()
{
    SetGenericTeamId(FGenericTeamId(5));
}

ABlueAIController::ABlueAIController()
{
    SetGenericTeamId(FGenericTeamId(1));
}

Found solution, maybe it’ll help someone:

HEADER:

UCLASS()
class RTS_API ATeamAIController : public AAIController
{
	GENERATED_BODY()
	
public:
	FGenericTeamId TeamId;

	UFUNCTION(BlueprintCallable, DisplayName = "SetTeamID", Category = "AI")
	void SetTeam(uint8 const& id)
	{
		TeamId = FGenericTeamId(id);
	}

	FGenericTeamId GetGenericTeamId() const override
	{
		return TeamId;
	}

	ETeamAttitude::Type GetTeamAttitudeTowards(const AActor& Other) const override;

};

CPP

ETeamAttitude::Type ATeamAIController::GetTeamAttitudeTowards(const AActor& Other) const
{
    if (const APawn* OtherPawn = Cast<APawn>(&Other)) {
        if (const IGenericTeamAgentInterface* TeamAgent = Cast<IGenericTeamAgentInterface>(OtherPawn->GetController()))
        {
            FGenericTeamId OtherTeamID = TeamAgent->GetGenericTeamId();

            if (OtherTeamID == TeamId)
            {
                UE_LOG(LogTemp, Warning, TEXT("Friendly"));
                return ETeamAttitude::Friendly;
            }
            else
            {
                UE_LOG(LogTemp, Warning, TEXT("Hostile"));
                return ETeamAttitude::Hostile;
            }
        }

    }

    return ETeamAttitude::Neutral;
}

Then from BP just call setTeam within begin play event.