How to use AI Touch Sense Config?

Hi Everyone !

I am using UE 4.27 and scripting with Blueprint.

I am trying to learn about AI with behavior trees, so I followed this tutorial. At the end, it introduces the AI Perception system with an AI Sight Config.

So I try now to add senses to my AI. Adding AI Damage Sense Config, I found out that calling “Report Damage Event” from my AI Blueprint triggers the “On Target Perception Updated” event in my AI Controller Blueprint.

But, when adding “AI Touch Config”, I am unable to trigger this event. Can someone help me please ?

Regards,

Felix

Hi, as far as I know that is not possible with blueprints. You would need to code your own “Report Touch Event” in c++, e.g. you could look here for how you could do that in c++ (second part of my post there) Setup AI touch sense in c++.

Hi ! Thanks for your reply.

It’s a shame that it is not possible with blueprints, I found the AI Perception system very efficient until here.

I am familiar with C++ but not with C++ in UE, so I do not really understand your reply on the attached post but I will read the Unreal documentation to fix this misunderstanding.

Thanks again

Hi !

So I learned about C++ in Unreal Engine and I tried the solution you proposed with the TeamStimulusEvent and tried to adjust it with the TouchEvent as you suggested in your linked post.

Unfortunately it is not working, let me give more details, I may do something wrong.

So this is my C++ static public method, inside a class derived from UBlueprintFunctionLibrary

void UNinjaSunsetLibrary::ReportAITouchEvent(AActor* InTouchReceiver, AActor* InOtherActor, const FVector& EventLocation)
{
	if (InTouchReceiver) {
		auto perceptionSystem = UAIPerceptionSystem::GetCurrent(InTouchReceiver);
		if (perceptionSystem) {
			auto touchEvent = FAITouchEvent(InTouchReceiver, InOtherActor, EventLocation);
			perceptionSystem->OnEvent(touchEvent);
		}
	}
}
  • My AI is defined in Blueprint as a Character.
    • Inside this Blueprint, I have set the “AI Controller Class” to “AIC_AIEnemyController” which is my custom Blueprint class derived from AIController.
  • Inside the “AIC_AIEnemyController” Blueprint, I have an “AIPerception” component.
    • I can trigger its event “On Target Perception Updated” with “AI Sight Config” and “AI Damage sense Config”.
  • My AI character has a capsule component, so on the event “On Component Hit” from this component I call my C++ method but the event “On Target Perception Updated” is not triggered.
    • I know that the event “On Component Hit” has been triggered due to some debug printing, so my C++ method does not have the expected effect.

Is there something I missed ?

Yes there is something I missed with the touch sense (now I got a minimalistic example to work, just to make sure I did not miss anything else… :slight_smile: ).
The TouchReceiver also needs to implement the IAIPerceptionListenerInterface (it is in "Perception/AIPerceptionListenerInterface.h"). So in your AI character you would need to implement that interface (where you would just return the AI perception component of its AI controller).

Ok thanks, but my AI Character is defined with Blueprint. I understand from your answer that I should create a new one in C++ to implement this interface, isn’t it ? Or is there a way to add a C++ interface inside a Blueprint Class ?

Yes you would need to implement that interface in c++. But you can then just reparent your blueprint AI character to the new c++ one, you won’t need to redo the blueprint.

Ok thanks ! I will try to do it