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?