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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Perception component for enemy AI not showing on C++

I've been trying to set up a simple perception system for a hack 'n' slash enemy AI, in which the enemy simply attacks the player if he sees him. In my base enemy class constructor, inheriting from ACharacter, I have:

 perception = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component"));
 sight = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Config"));

However, when creating an enemy inheriting from this class, the perception component isn't there and there's no sense config options or any way to register the stimuli. I've also tried changing the perception component to a UPawnSensing class, but it still doesn't appear.

How do I make this perception component work?

Product Version: UE 4.12
more ▼

asked Oct 11 '16 at 08:26 AM in C++ Programming

avatar image

5 2 5 6

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

1 answer: sort voted first

Hey Herreteman,

I think the perception component should mostly be used on the AIController rather than the character.

Then you can use the functions SetPerceptionComponent() & GetAIPerceptionComponent()

It will become something like this in MyCustomAIController.cpp :

 SetPerceptionComponent(*ObjectInitializer.CreateDefaultSubobject<UAIPerceptionComponent>(this, TEXT("AIPerception Component")));
 UAISenseConfig_Sight* sightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Config"));

Hope this helps :)

more ▼

answered Oct 11 '16 at 09:21 AM

avatar image

1.2k 24 16 53

avatar image Herreteman Oct 11 '16 at 04:38 PM

This solved it, thanks! I should study the base C++ classes a bit more, since I didn't know that AI Controller was a separate class.

(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