Function already has a body

i had been trying to do like the youtube tutorial of creating a pickup battery( - YouTube
)[link text][1] the BasePickup was okay but after writing the BatteryPickup class it is showing like this
" Error 1 error C2084: function ‘ABatteryPickup::ABatteryPickup(void)’ already has a body C:\Users\Benhur joseph\Documents\Unreal Projects\Pickup\Source\Pickup\BatteryPickup.cpp 8 1 Pickup"

here is my BatteryPickup,h

and here is my BatteryPickup.Cpp

please help me to get rid of this problem .thank you.

Hello,

can you show your base APickupActor header file listing? Anyway in your current class definition you didn’t define constructor method:
ABatteryPickup();

thank you very much for replying .
here is the bas ApickupActor.h

and this is the ApickupActor.cpp

(ApickupActor.cpp also contains the BlueprintNativeEvent defined which is not shown in the image.it is defined as shown below .
.
//define what happens when picked up
void APickupActor::OnPickedup_Implementation()
{
//there is no default behavior
}

iam totally new to these programming . so hope you elaborate on my mistakes.thank you.

  • in PickupActor.h you don’t need to define OnPickedup_Implementation. That’s one of those things that engine does for you itself.
  • in BatteryPickup.h you need define default constructor for class - I mean ABatteryPickup();. For now you do implement it in *.cpp file but don’t define in *.h file

PS: I’m myself beginner with all this UE stuff.

successfully builds for me

This documetation page explains behavior of BlueprintNativeEvent specifier.

thank you for pointing out my careless mistake . but something about the buleprintNative Event i done here .

i removed the " virtual void OnPickedup_Implementation() " line from the APickupActor.h but then i cannot override it in my ABatteryPickup class . the override defining line “void OnPickedup_Implementation()override;” will shown as as a error

Can you attach zip with these 4 files PickupActor.h & .cpp and BatteryPickup.h & .cpp? I’ll see what may be wrong

link text

It seems that you didn’t rename your #include statements. They’re the same as in example #include “Pickup.h”, but your files have different name

My bad, I didn’t notice that at beginning

i don’t think that is a problem because Pickup.h is the project file . my project’s name is Pickup. also all the #include are automatically added by visualstudio when i created the class in unreal editor using class wizard . i didn’t mess anything there .

Try rebuilding your project, _Implementation function need to be generated in order to be overrided by compiler

i tried rebuilding it and many other possibilities like making it virtual void in cpp file for writing the function , but every time i got error at the same place saying Onpickedup_Implemetation is not a member of ApickupActor .i guess for overriding from a base class OnPickedup_Implementation needs to be defined as a virtual void in the header file.