Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AIPerception - Affiliation implementation in C++

Hi everyone,

I’m trying to implement AIPerception by Affiliation (Enemies, Neutrals, Friendlies), but I’m struggling to find the correct way for the implementation in C++

I’m very unexperienced with C++ in Unreal 4 and hopefully someone can point me into the right direction for this. Any help is really appreciated.

The main question is where and how I could set the affiliation. I’m also not sure if it has to be on the character, the controller or both...

Thank you in advance.



Product Version: UE 4.14
more ▼

asked Dec 10 '16 at 08:01 PM in C++ Programming

avatar image

Terry J. N.
40 1 3 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Hi Terry,

Take a look inside AIModule/Classes/GenericTeamAgentInterface.h. Basically you need to implement that interface in you characters or PlayerController (as you prefer), AIController already implement that. Override the following function from that interface to get and set the Team of that entity

 virtual void SetGenericTeamId(const FGenericTeamId& NewTeamID);
 virtual FGenericTeamId GetGenericTeamId() const

Bind a function to OnTargetPerceptionUpdated in you AIController to be notified each time the perception system is updated

 UAIPerceptionComponent* PerceptionComp = GetAIPerceptionComponent();
 if (PerceptionComp) 
     PerceptionComp->OnTargetPerceptionUpdated.AddDynamic(this, &ABaseAIController::OnTargetPerceptionUpdated); 

Now, in your OnTargetPerceptionUpdated you can get the "Team Attitude" of you AIController toward the senced actor

 void AMyAIController::OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus Stimulus)
     IGenericTeamAgentInterface* TeamAgent = Cast<IGenericTeamAgentInterface>(Actor);
     if (TeamAgent)
         ETeamAttitude::Type AttitudeTowards = GetTeamAttitudeTowards(*Actor);
         //Now in AttitudeTowards you have the attitude (Friendly, Neutral, Hostile,) at this point you only need to check and do wetherever you want based on that attitude. if is Hostile, attack, if is Neutral, ignore etc ... For example:
         // Don't do anything if the attitude towards sensed actor is neutral. 
         if (AttitudeTowards == ETeamAttitude::Neutral)

also you can override GetTeamAttitudeTowards if you want to change how retrieve owner attitude toward the given actor

Hope this help you

Best regards Fernando

more ▼

answered Dec 12 '16 at 01:23 PM

avatar image

502 23 13 38

avatar image nan2cc Dec 12 '16 at 01:29 PM

Remember that both entities AIController and the sensed actor (the entities that implement the interface) should be in some team, not just the sensed actor also you need to define the AIController's team, based on your gameplay teams logic.

avatar image Terry J. N. Dec 14 '16 at 09:33 AM

Thank you, that's what I was looking for.



(comments are locked)
10|2000 characters needed characters left
Viewable by all users

You''ll want to create enums that store different factions or whatever you're looking for, ie

 enum class EFactionType : uint8

And then give each monster or player a Faction. Also add an TArray that the monster is aggressive against. When the enemy sees you, check that your faction is an enemy faction, and if it is, then begin attacking the player. I won't go into more detail about the AI stuff, because it would take too long, but you're welcome to view my tutorials if you want some info on AI. You can search Reuben Ward on youtube.

Hope this helps!

more ▼

answered Dec 10 '16 at 11:02 PM

avatar image

Denzel Jerry
27 4 7 9

avatar image Terry J. N. Dec 11 '16 at 12:39 PM

Hey Denzel (or Reuben) :)

Thx for your quick reply. I had a similar solution in BB using actor tags like friendly, neutral, enemy, ... however, this does not feel like the correct/native way to do it and was way too much overhead (in my personal opinion).

We already have a native UE4 solution that is build in and I can’t get my head around how to use it:

alt text

The detection by affiliation must be there for a reason? I've seen AI tutorials that are more than one year old but everyone just suggests to tick all three detection types when it comes to use it with the AI perception system.

I’ll dig into your videos, maybe I’ll find what I’m looking for.

Thank you & Cheers Terry

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question