hi all, i have some issue when i trying to override my c++ function with blueprint.
i have a class A.h :
and A.cpp :
// there is no default behavior to the item when it is picked up
and a class B, a child of classe A ( class B : public A )
void OnPickedUp_Implementation() override;
//call the parent implementation first
FString test = "its works";
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, test);
/* Destroy the Coin */
and my blueprint :
when i pickup a item , the function OnPickUp is called , the item is detroy and a message appear in the game . but the blueprint override is not call.
if i make a link between "Event Destroy"and “Play sound at location”, this work so is not a blueprint probleme.
What i do wrong ?
I Have found there is a certain methodology to the madness when it comes to using UE4. Because of the layers of indirection between the C++ code you write, the the C++ code generated by the UBT, to the way blueprints implement things can get a bit confusing. The first and foremost is I do not think your PickedUp_Implemented is marked virtual in your A.h class and I don’t think you can mark it virtual either. This is most likely why your changes are not being called.
How I would solve this is to create a function in your base class A.h
virtual void PickedUp();
The make your implementation function in A.cpp
// do something
Now if you need to implement something new in C++ in your B class you can override the PickedUp function.
virtual void PickedUp() override;
// Do Custom Stuff here
// Call Super::PickedUp()
// Or do custom stuff here
// Or forget Super and just call OnPickedUp() it's protected after all
I have a bit of an Update to this, while this method works you may be able to specify that a Function_Implementation is virtual afterall. I stumbled across a UFunction specifier called CustomThunk Through some random sequence of events I learned that UE4 calls the generated _implementation functions “thunks”. Unfortunately I do not know more than this but figured it may be useful to you to play round with.
Function void A::OnPickedUp(); is virtual. If it wasn’t
void B::OnPickedUp_Implementation() override; would not compile as You cannot override non virtual functions