Client crashes when i try to set values on my sight config in my AI controller BP

I have been working a bit with AI for a project but have an issue with trying to set values on the AI’s sight config on the AI perception component of the AI. Every time i try to set a value the client crashes and gives me this crash report.

I have the code where i create the config below.

Any help would be appreciated, i have been testing a bit but cannot figure out why it is crashing for me.

MachineId:
EpicAccountId:

Access violation - code c0000005 (first/second chance not available)

""

UE4Editor_PropertyEditor!FPropertyNode::PropagatePropertyChange() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\editor\propertyeditor\private\propertynode.cpp:2390]
UE4Editor_PropertyEditor!FPropertyValueImpl::ImportText() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\editor\propertyeditor\private\propertyhandleimpl.cpp:426]
UE4Editor_PropertyEditor!FPropertyValueImpl::ImportText() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\editor\propertyeditor\private\propertyhandleimpl.cpp:297]
UE4Editor_PropertyEditor!FPropertyHandleFloat::SetValue() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\editor\propertyeditor\private\propertyhandleimpl.cpp:2160]
UE4Editor_PropertyEditor!SPropertyEditorNumeric<float>::OnValueCommitted() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\editor\propertyeditor\private\userinterface\propertyeditor\spropertyeditornumeric.h:254]
UE4Editor_PropertyEditor!TBaseSPMethodDelegateInstance<0,SPropertyEditorNumeric<float>,0,TTypeWrapper<void> __cdecl(float,enum ETextCommit::Type)>::Execute() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:282]
UE4Editor_PropertyEditor!TBaseSPMethodDelegateInstance<0,SPropertyEditorNumeric<float>,0,void __cdecl(float,enum ETextCommit::Type)>::ExecuteIfSafe() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:388]
UE4Editor_PropertyEditor!SSpinBox<float>::CommitValue() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\public\widgets\input\sspinbox.h:614]
UE4Editor_PropertyEditor!SSpinBox<float>::TextField_OnTextCommitted() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\public\widgets\input\sspinbox.h:544]
UE4Editor_PropertyEditor!TBaseSPMethodDelegateInstance<0,SSpinBox<float>,0,TTypeWrapper<void> __cdecl(FText const & __ptr64,enum ETextCommit::Type)>::Execute() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:282]
UE4Editor_PropertyEditor!TBaseSPMethodDelegateInstance<0,SSpinBox<float>,0,void __cdecl(FText const & __ptr64,enum ETextCommit::Type)>::ExecuteIfSafe() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:388]
UE4Editor_Slate!SEditableText::OnEnter() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\widgets\input\seditabletext.cpp:973]
UE4Editor_Slate!FTextEditHelper::OnKeyDown() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\framework\text\textedithelper.cpp:191]
UE4Editor_Slate!SEditableText::OnKeyDown() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\widgets\input\seditabletext.cpp:1637]
UE4Editor_Slate!<lambda_4f604f87f3ce3f5c3b6a1447676ad634>::operator()() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:3750]
UE4Editor_Slate!FEventRouter::Route<FReply,FEventRouter::FBubblePolicy,FKeyEvent,<lambda_4f604f87f3ce3f5c3b6a1447676ad634> >() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:212]
UE4Editor_Slate!FEventRouter::RouteAlongFocusPath<FEventRouter::FBubblePolicy,<lambda_4f604f87f3ce3f5c3b6a1447676ad634>,FKeyEvent>() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:194]
UE4Editor_Slate!FSlateApplication::ProcessKeyDownEvent() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:3751]
UE4Editor_Slate!FSlateApplication::OnKeyDown() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:3675]
UE4Editor_Core!FWindowsApplication::ProcessDeferredMessage() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\windows\windowsapplication.cpp:1262]
UE4Editor_Core!FWindowsApplication::DeferMessage() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\windows\windowsapplication.cpp:1711]
UE4Editor_Core!FWindowsApplication::ProcessMessage() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\windows\windowsapplication.cpp:706]
UE4Editor_Core!FWindowsApplication::AppWndProc() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\windows\windowsapplication.cpp:628]
user32
user32
UE4Editor_Core!FWindowsPlatformMisc::PumpMessages() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\windows\windowsplatformmisc.cpp:792]
UE4Editor!FEngineLoop::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\launchengineloop.cpp:2319]
UE4Editor!GuardedMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\launch.cpp:142]
UE4Editor!GuardedMainWrapper() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]

I assume that it is because of how i created the sight config in my C++ since it is giving me access violation.
This is how i create the AI perception and the sight config.

In my controller header.

public:
    // AI Perception component used for sensing actors
    UPROPERTY(EditAnywhere, Category = "AI Sensing")
    UAIPerceptionComponent* PerceptionComp;
    
    UPROPERTY(EditAnywhere, Category = "AI Sensing")
    UAISenseConfig_Sight* SightConfig;

In the constructor

// Setup the perception component
PerceptionComp = ObjectInitializer.CreateDefaultSubobject<UAIPerceptionComponent>(this, TEXT("AIPerception Component"));
SightConfig = ObjectInitializer.CreateDefaultSubobject<UAISenseConfig_Sight>(this, TEXT("Sight Config"));
PerceptionComp->ConfigureSense(*SightConfig);
PerceptionComp->SetDominantSense(SightConfig->GetSenseImplementation());
PerceptionComp->OnPerceptionUpdated.AddDynamic(this, &AMurdererController::AISense);

and in the OnPosses function.

// Setting values of AI perception component configs
SightConfig->SightRadius = ControlledPawn->SightRange;
SightConfig->LoseSightRadius = ControlledPawn->LoseSightRange;
SightConfig->PeripheralVisionAngleDegrees = ControlledPawn->PeripheralVisionAngle;
SightConfig->DetectionByAffiliation.bDetectEnemies = true;
SightConfig->DetectionByAffiliation.bDetectNeutrals = true;
SightConfig->DetectionByAffiliation.bDetectFriendlies = true;
PerceptionComp->ConfigureSense(*SightConfig);

Although the callstack doesn’t directly indicate AI Perception origin, it is possible it’s due to your setup (even though it seems you did nothing wrong!).

I’ve got a feeling I know what’s wrong. The code issue would be that SightConfig is owned by AIController (BTW, try using NewObject rather than CreateDefaultSubobject, and mark that property Transient since it seems you don’t intend to save it anyway), while when it’s being passed over to ConfigureSense the pointer gets stored in AIPerceptionComponent's array (assuming ownership). I “feel” this is trouble.

I’d suggest creating your own perception component class by deriving from AIPerceptionComponent and adding hardcoded Sight config.

Let me know what you find.

Cheers,

–mieszko

What kind of issues? Do you have AIModule in your project’s dependencies, in the Yourproject.build.cs file?

Add following header in front of AISenseConfig_Sight.h:

#include "Perception/AISense.h"

I decided to create my own perception class that derives from AIPerceptionComponent, but i’m unsure how to include the config as i cannot include the header #include "Perception/AISenseConfig_Sight.h" as i causes some issues.

Yeah, i have the module included.
When i include the header i get these errors.

1>c:\program files\epic games\4.8\engine\source\runtime\aimodule\classes\perception\AISenseConfig.h(29): error C2027: use of undefined type 'UAISense'
1>          c:\program files\epic games\4.8\engine\source\runtime\aimodule\classes\perception\AIPerceptionTypes.h(10) : see declaration of 'UAISense'
1>c:\program files\epic games\4.8\engine\source\runtime\aimodule\classes\perception\AISenseConfig.h(29): error C2027: use of undefined type 'UAISense'
1>          c:\program files\epic games\4.8\engine\source\runtime\aimodule\classes\perception\AIPerceptionTypes.h(10) : see declaration of 'UAISense'
1>c:\program files\epic games\4.8\engine\source\runtime\aimodule\classes\perception\AISenseConfig.h(29): error C2027: use of undefined type 'UAISense'
1>          c:\program files\epic games\4.8\engine\source\runtime\aimodule\classes\perception\AIPerceptionTypes.h(10) : see declaration of 'UAISense'
1>c:\program files\epic games\4.8\engine\source\runtime\aimodule\classes\perception\AISenseConfig.h(29): error C2027: use of undefined type 'UAISense'
1>          c:\program files\epic games\4.8\engine\source\runtime\aimodule\classes\perception\AIPerceptionTypes.h(10) : see declaration of 'UAISense'

Yeah, that worked. I’m not getting the errors anymore.

Edit: It wasn’t NewObject after all. It was just a problem of our friend hot reload. It works fine with CreateDefaultSubObject.

@MieszkoZ thanks for your incredible work.

I had the same problem and I fixed it by using NewObject instead of CreateDefaultSubobject.

The error is fixed but could you please explain to me why should we use NewObject? I’ve seen that it’s widely used in the AIModule.

Many Thanks.

Cheers,