AI Perception crashes every time the Stimuli Source registers as Source

Hi, I was just checking out the AI Perception system in v4.8 and noticed that the editor always crashes when the ‘AIPerceptionStimuliSource’ adds an element for ‘Register as Source for senses’. I’ve reproduced it in the base Top Down template with no other changes. Just add the AIPerceptionStimuliSource for the TopDown Character and press add in Register as source for senses.

I’ve attached a screenshot of the same and a text file containing the crash report data.

[CrashReportData][2]

Too late, this has already been fixed :stuck_out_tongue_winking_eye:

The reason it “crashes” is that the piece of code processing the array in question treats null values as invalid, while it’s a common case while editing the array. The workaround would be to uncheck the Auto Register as Source flag, modify the array and enable the flag back.

A side note, Pawns get always auto-registered as sight-sources, so if that’s your reason to play around with that then stop, it’s already done automagically :slight_smile:

Cheers,

–mieszko

Glad to hear that it’s fixed. In cases like these, it’s better to hear that I’m late :stuck_out_tongue: Thanks for the workaround. I’ll try that out.

Looks like the AIPerceptionStimuliSourceComponent still has a bug (which is why this “crash” was happening in the first place).
In OnRegister, it’s doing this:
RegisterAsSourceForSenses.RemoveAllSwap([](TSubclassOf SenseClass){
return SenseClass != nullptr;
});

but the comparison should be SenseClass == nullptr. That is, assuming the intention was to remove all null entries from the RegisterAsSourceForSenses TArray.

The current implementation ONLY keeps null Senses in the array. So, the check(SenseClass) was actually the right thing to do! We just need to fix the RemoveAllSwap comparison.