Crash after adding C++ component

Hi,

After creating a new C++ component in visual studio and building it there, my Unreal Editor crashes and I am unable to open my project again. It is not happening all the time so I assume it is connected to the code I wrote, but I am not sure if it is just me or it is editor’s global issue. Code that makes crashes: link:here

AActor* Owner = GetOwner();
AActor* ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();

Don´t do this in your Header. Initialize your Variables in the Constructor instead.

Hey arkadeusz91-

The likely cause of the crash you’re seeing is the GetWorld() call being made. Since the world is only valid during runtime, this call is returning null which is causing the crash. Doing a check to make sure the world exists first ( if(GetWorld())) should help prevent the crash. This goes along with 's suggestion of moving the code from the header file to the constructor of the source file and doing the if() check there.

Cheers