Help with compiler error with "Introduction to UE4 Programming" Tutorial

I’m following the Introduction course for UE4 programming, and have reached part 4, but when I try to compile the code I get a error C3668, havve been looking around, but the one answer I found, did not in any way explain the problem or how to fix it… at least not for me.

My set up is Windows 7 64, UE4.6.1 and I use MVSExp 2013

My code so far is:

This is my BatteryPickup Code, with the error:

This is the previous 2 files from the earlier lesson:

Not able to upload the screenshot, so here’s the code for the Pickup.h file

UCLASS()
class TUTORIALBATTERY_API APickup : public AActor
{
	GENERATED_BODY()

public:
	APickup(const FObjectInitializer& ObjectInitializer);

	/* True when the pickup is able to be picked up, false if something deactivates the pickup. */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pickup")
		bool bIsActive;

	/* Simple collision primitive to use as the root component*/
	UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Pickup")
		USphereComponent* BaseCollisionComponent;

	/* StaticMeshComponent to represent the pickup in the lvl */
	UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Pickup")
		UStaticMeshComponent* PickupMesh;

	/* Function to call when the Pickup is collected */
	UFUNCTION(BlueprintNativeEvent)
		void OnPickedUp_Implementation();


};

Hope you can help me to identify the cause of the problem and rectify it.

Hi Hardishane,

You have this error cause you cannot override non-virtual function. Also BlueprintNativeEvent means that this function is designed to be overridden by a Blueprint, but also has a native implementation. Provide a body named [FunctionName]_Implementation instead of [FunctionName]; the autogenerated code will include a thunk that calls the implementation method when necessary.
You should declare you function like that:

PickeUp.h
UFUNCTION(BlueprintNativeEvent, category = adfs)
void OnPickedUp();  // Cannot be virtual cause BlueprintNativeEvent specifier

PickeUp.cpp
void APickeUp::OnPickedUp_Implementation()
{
	// to do smth here. This function is generated by UHT and it is virtual, you can override it in derived classes.
}

Best regards,

Hi

I Take it that its a bit tricky for a new-come programmer to use the _Implementation in header files, and that if not totally sure you should avoid it :slight_smile:

Thanks for the answer, solved my problem elegantly :slight_smile: