ue4 crash - "...not being constructed..." (beginner problem)

This is for looting range for the player. A bool value is set to true when the player enters a triggerbox and false upon leaving (false on default). In the character controller the player can loot if (true) and not if (false). However, the bool-getter-function is causing the engine to crash.

Error: Fatal error: …RightMouseButton is not being constructed with either NewObject, NewNamedObject or Construct

Expected behavior: I want the get function to return a boolean from the Pickup class.

Observed behavior: Engine crash upon clicking Right mouse button (bound key to Interact function)

Steps to reproduce: Trying to call a function from another class by doing what ever i am doing.

What has been tried already: I’ve obtained wanted result outside ue4.

Useful info: ue4 v.19, vs: v.15.7.6

c++ Character

// Input setup
void APlayerCharacterController::SetupInputComponent()

    InputComponent->BindAction("Interact", IE_Pressed, this, &APlayerCharacterController::Interact);

// Called on RightMouseButton
void APlayerCharacterController::Interact()
    APickup PickupClass;
    if (**PickupClass.GetInLootRange()**)
        if (CurrentInteractable)
        UE_LOGS(LogTemp, Warning, TEXT("Out of loot range"))

The syntax is incorrect. I’m surprised it compiles to be honest.

You need to spawn an APickup actor to be able to call functions on it, and you call functions on a pointer to the object, not a copy of it. Example:

APickup* Pickup = GetWorld()->SpawnActor(APickup::StaticClass);
if (Pickup->GetInLootRange())


In general however it looks like the approach to this code is very off. I would recommend looking at the example projects that are available for C++ before trying to create something of your own, C++ is a very different syntax to what you’re writing there.

Ok, i will do that… thanks