Unreal Engine crashes declaring pointer in .h file

Hello everyone!

Why unreal engine crashes when i initialize a pointer in the .h class file (img1), but it doesn’t crash when i initialize it into .cpp file, inside the BeginPlay function (img2). Have you any idea about it?. it’s happened with too many others pointers…

It’s not exactly clear what your code is when you are doing it in the header. Do you mean you have this in the header

UPhysicsHandleComponent PhysicsHandle = nullptr;

and then this in the CPP?

GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();

Because that would mean PhysicsHandle will always be nullptr. You never assign it a value afterwards. That line in the cpp should be

PhysicsHandle = GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();

From the UE Course ( Unreal Engine C++ Developer: Learn C++ and Make Video Games) (video 122 - FindComponentByClass), i’m simply trying to create the pointer, just like the video shows, using FindComponentByClass function.
If i create the pointer to Nullptr into .h file (like img1 shows), unreal Crashes, but if i just create the pointer into .cpp file (like img2 shows), the editor doesn’t crash.

Can you paste Screenshot of the Crash Error report and Unreal Editor compiling log like in second attached screenshot

Also check did you save yourself everywhere with such checks
if (PhysicsHandle) {
where you using it

Thanks, here more images (new1, new2):

I can’t reproduce your problem
Looks like something wrong with your class build files, but cant say more, I am new too…

Yes, i hope somebody can help me :C

That doesn’t appear to be crashing from BeginPlay looking at that crash report. Could you try a full rebuild?

Close Unreal and delete your Binaries and Intermediate folders then reopen your project rebuilding when prompted.

1 Like

Effectively it was a bug, i tried to delete both Binaries and Intermediate folders and it worked! (before i only deleted the Binaries folder). Thanks a lot, have a great week!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms