Project no longer opens without crashing after adding UPhysicsHandleComponent logic

Today I started working towards a way to pick up objects, adding this functionality to existing project/solution. Initially the scripts compiled with no errors, then I hit play to test it out and it crashed with this error, referencing line 47 of my ItemGrabber.h header file:

UObject() constructor called but it's not the object that's currently being constructed with NewObject. Maybe you are trying to construct it on the stack, which is not supported.

This is the log from Rider for Unreal Engine:

Here’s the full log output from Unreal:
https://pastebin.com/8FN8M1X9

Line 47 is just a float variable declaration:

float Reach = 1000;

So I reloaded the project, and it crashes with the same error. Changing the default map does not work. I also tried commenting out the code I added that began these crashes, with no luck. I’d get the same error but on different seemingly unrelated lines in the same header file.

Deleting the script files entirely also does not solve the crash, and it references the same header file and same line.

Here’s the two scripts in question:
ItemGrabber.h: ItemGrabber.h - Pastebin.com
ItemGrabber.cpp: ItemGrabber.cpp - Pastebin.com

Google searches suggested adding UPROPERTY() to pointers like PhysicsHandle, and Rider is also warning me “Object member ‘PhysicsHandle’ can be garbage collected at any time”, but either way that didn’t solve the crash nor change the error.

I also think this error started happening once I added the check for PhysicsHandle for logging, but I’m not sure… I can’t remember.

The crashing started after adding the following lines to ItemGrabber.cpp:

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

if (!PhysicsHandle) {
	UE_LOG(LogTemp, Error,
		TEXT("%s has no Physics Handle Component (needed by ItemGrabber)!"),
		*GetOwner()->GetName()
	);
}

And the matching lines on the header file:

UPROPERTY()
UPhysicsHandleComponent* PhysicsHandle = nullptr;  

I’m not sure how to format / color code on this site.
Any ideas what I messed up here?

Cleaned and rebuilt entire solution. Some #includes needed to be rearranged, but after a successful rebuild, I still get the same error with the same line number mentioned.

I reckon it’s because of that (ItemGrabber.h):

 AActor GrabbableActor; // Probably missing *

You are trying to create new AActor during construction of static object for UItemGrabber, AActor cannot be created on “stack”.

As for UPROPERTY with

UPhysicsHandleComponent* PhysicsHandle = nullptr;

from what I see the Physics handle is created somewhere else, but in here you are simply storing a pointer to it, it would be better to use TSoftObjectPtr than raw C++ pointer. Long story short, TSoftObjectPtr is a weak pointer that will get “invalidated” once the object it points to is destroyed.

In your example, if the actual object gets deleted, you are left with a dangling pointer to a memory that is no longer occupied by the object and dereferencing it will cause undefined behavior.

You could also you UPROPERTY with the c++ raw pointer, which is going to do the same thing (more or less) but in that case, the object is reference counted additional time, that means it won’t get automatically deleted if it goes “out of scope”.

I’ve completely deleted the ItemGrabber.h and ItemGrabber.cpp files, cleaned and rebuilt the entire solution, and I still get an identical error referencing ItemGrabber.h when attempting to open the uproject. I’m pretty lost here.

I completely deleted the entire Source folder, and it still results in an identical crash when opening the Unreal project, referencing the same header file and lines in the log.

I must be unaware of some config or cache file/folder stored somewhere.