Complete Quest¶
Let’s replace the CompleteQuest BP function with one in C++.
Take a look at the node and details:
We notice that.
This is a Public function
It is not Pure
The Inputs are:
QuestId of type Name and not passed by reference.
CompleteWholeQuest of type Boolean and not passed by reference.
There are no output
There is a pi going in named Index
Create the CompleteQuest C++ Function¶
In QuestManager.h add
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void CompleteQuest(FName QuestId, bool CompleteWholeQuest);
In QuestManager.cpp add
void AQuestManager::CompleteQuest_Implementation(FName QuestId, bool CompleteWholeQuest)
{
}
Overriding CompleteQuest¶
Grab all but the input node from CompleteQuest BP, Ctrl-X to cut.
Delete CompleteQuest
Override the function CompleteQuest.
Paste the graph.
Noteice that we see Event Complete Quest. So it appears as an event. This is the case if the function return is void.
The function is void
Is not const
Right click on Event Complete Quest and select Add call to parent function
Overriding GetQuestIndex¶
Notice GetQuestIndex that is only available in Blueprint.
That would need to be migrated.
Also notice that the Output is Index which would not match C++.
Rename that to Return Value which is a special name in Blueprint would fix that.
Add the below to QuestManager.h
UFUNCTION(BlueprintPure, BlueprintImplementableEvent)
int32 GetQuestIndex(FName QuestId);
Ctrl-X cut the content of the GetQuestIndex, delete and override with same name. Hook up the wires correctly
4: Fix the below error by Right-Click Refresh Node and reconnect.
Implementing CompleteQuest¶
Add code to QuestManager.cpp
void AQuestManager::CompleteQuest_Implementation(FName QuestId, bool CompleteWholeQuest)
{
int32 QuestIndex = GetQuestIndex(QuestId);
FQuestInfo Quest = QuestList[QuestIndex];
if (CompleteWholeQuest) {
QuestList[QuestIndex].Progress = Quest.ProgressTotal;
}
else {
QuestList[QuestIndex].Progress = FMath::Min(Quest.Progress + 1, Quest.ProgressTotal);
}
}
All nodes pasted from before was used only for reference to replicate as code above. Now delete them.
connect input to calling parent to output along with GetQuestIndex and we have replaced the BP function in C++.