Can't avoid read access violation - In debugger, the object is showing up as completely wrong type.

I am trying to find an actor (AItemEntity) or spawn one in if it doesn’t exist already, but am getting read access violation even with nullptr and IsValid() checks:

In the debugger, it says that my field (accessed with GDItem->GetActor()) is set to one of the static mesh components from the ASecondNightCharacter (this class), when the field type is AItemEntity (class SECONDNIGHT_API AItemEntity : public AActor, public ISecondNightEntity):


Screenshot 2023-06-20 083658

Here is how the field is being set:

I’m guessing this may just be a bit of a glitch in the debugger, and that the field is just somehow invalid, but I don’t know how to check if the field is good when IsValid() and != nullptr checks both pass.

Bump?

Can you show what AGameData::Item declaration looks like

AGameData::Item is just an internal nested class use for tracking data.

I see you are not using UE decorators. Is there any particular reason for that ?

Without UE memory management (brought by decorators), neither comparing to nullptr nor using IsValid() is enough to guarantee the pointer points to a valid object.

You should use FWeakObjectPtr or TWeakObjectPtr<AItemEntity> to hold your references instead, if you don’t want to use managed variables.

Okay. Thanks, I will try that out. I wasn’t using them because of the extra verbosity, and didn’t realize they were that necessary.