AI Perception register source issue

Hey so I was messing around with the AI Perception System in blueprint and i’m getting a really weird issue. Most of the time when I call the Register Source blueprint node it works fine. However after a little while (usually after restarting the editor a few times) the Register source nodes seem to break. They trigger a breakpoint here at the ensure function:

void UAIPerceptionSystem::RegisterSource(FAISenseID SenseID, AActor& SourceActor)
{
	ensure(IsSenseInstantiated(SenseID));
	SourcesToRegister.Add(FPerceptionSourceRegistration(SenseID, &SourceActor));
}

The only way to get around it once it starts doing this is to completely recreate the blueprint. Even if I remove the node and add it back the problem persists until I make a new version of the blueprint. So far its done this with blueprints based off of pawn, character, and several other custom c++ ones that are also based off of pawn or character. Here is a link to my call stack when I hit the breakpoint: http://pastebin.com/MvNSafaG

Here is the actual error that crashes the editor: Array index out of bounds: 255 from an array of size 1

Not sure if its related but also sometimes when I get this issue the node will change from requiring the sense class and the target object to one that also requires a world context.

Edit: So after talking with some people on the UnrealEngine IRC channel Ashyre figured part of it out for me. Essentially I had to make some changes to the AIPerceptionSystem.cpp

On line 399 I removed the const

Then I insterted a new line at 403 SenseID = UAISense::GetSenseID(Sense);

The end result being:

 FAISenseID SenseID = UAISense::GetSenseID(Sense);
 if (AISys->GetPerceptionSystem()->IsSenseInstantiated(SenseID) == false)
 {
      AISys->GetPerceptionSystem()->RegisterSenseClass(Sense);
      SenseID = UAISense::GetSenseID(Sense);
 }

However, after some more experimentation I realized that while this didn’t actually fix the problem it made it reproduce regularly. Essentially whenever I restart the editor the Register node changes and the game crashes with this call stack: http://pastebin.com/3GbKq2VH

I have tried attaching stuff to the world context but it doesn’t fix anything.

Thanks,

-Chris

It seems you’ve found a bug in the way perception system exposes its functions to BP. Can you try supplying a context, like “self”, to the Register Perception Stimuli Source? It’s possible it’s crashing due to this parameter getting hidden while the value is None, which would lead to a crash.

Cheers,

–mieszko

Ok thanks for the reply! How would I go about supplying it with a context? Would that be something I would do in code? I know in the blueprint I supply “self” but like you said there might be something going on with it.

Like so:

39452-self.png

Where you obratainSelf like so:

39453-self2.png

So I spoke too soon apparently, it was working fine then all of the sudden after a few editor restarts it stopped working again with the same error that I’ve been getting lol.

So I’m really not sure what the issue is, I’m getting some really strange things happening. I’m starting to think there may be some weird issue with my project because it tends to break after a few editor restarts. I saw zoombapup did a brief overview of it today and his setup looks the same as mine so i’m probably going to try and get this setup and working on a blank project and go from there.

Are you able to grab UE4’s github sources, master branch, and give that a go? I’ve just submitted a bunch of perception system fixes.

Yeah I can. I’ll give that a go and let you know what happens, thanks!

Well so far everything looks good no major crashes relating to the bug! There is one small crash still but its just when you drag out a pin from target it will crash: Unhandled GraphSchemaAction, wanting a menu icon: FEdGraphSchemaAction
I can still attatch stuff to it just can’t drag anything off.