Crash because of GetWorld()

I am creating a AIController however UE4 crashes because of this line(30):

MyAIController.h in the second photo.
(On this line, I try to get all the actors on this world, but because of it, ue4 crashes)
Unreal Crash Report:

How do you know GetWorld is the cause of the crash? Does it crash it you comment lines 30 and 31 and replace them with a simple GetWorld();

Yes, you are right, the error is on another line, at 28 (By commenting, I realized that it was exactly her) However, what is wrong in it?


I’m not in front of a UE4 computer at the moment but do you need to do an include to the UGameplayStatics?

#include "Kismet/GameplayStatics.h

I also notice, which is completely unrelated but there’s a typo in your header file:

FORCEINLINE TArray<AActor*>GetAvaitableTargetPoints()

Avaitable instead of available :slight_smile:

Ah ok that got updated as i was writing this…

I don’t know if I’m following your code correctly but i notice that you’ve called the blackboard component ‘BlackboardComp’ in your header file but in the constructor you’re creating the object on line 16 by calling it just ‘Blackboard’.

Then on line 28 you’re calling BlackboardComp.

Or may have totally not followed what your code is doing :slight_smile:

A missing header would probably throw a compiler error, not a crash. The issue is probably one of the pointers.

Check all of your pointers, most likely one of them is null, which would explain the crash.

I assume this will fail somewhere:

if (BlackboardComp && AIChar && AIChar->BehaviourTree && AIChar->BehaviourTree->BlackboardAsset)

Yeah i would have thought blackboard variable being wrong would have thrown a compiler error aswell as the include not being there but C++ melts my brain sometimes :slight_smile:

have you tried running ue4 whilst attached to Visual Studio, would that not break to the problem and give a more informative error when it crashes?

By coincidence, the two variables Blackboard and BlackboardComp were initialized and the compiler did not give an error, but you probably just assumed I noticed this, and it really was an error, thanks a lot. Of course, I got another error, the index exit from the boundaries of the array, but to solve it, I have to search the entire project, so I will try to fix it myself.

Just a suggestion, always protect your pointers!!
Your best friend in c++ is: if( !pointer ){ return; } ^^