Dialogue System

Hi there.

I implement dialogue parameter for my project. If you think it is usefull, integrates it. I put this in BTDialoguesTypes.h


/**
* Dialogue Argument Struct
*/
USTRUCT()
struct DIALOGUESYSTEM_API FDialogueParameter
{

	GENERATED_USTRUCT_BODY()

public:

	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = DialogueParameter) FString StringKey;
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = DialogueParameter) FBlackboardKeySelector BlackboardKey;

public:

	void PushArgument(FFormatNamedArguments& DialogueArguments, UBehaviorTreeComponent& OwnerComp) const
	{

		UBlackboardComponent * Blackboard = OwnerComp.GetBlackboardComponent();
		FString TextValue = Blackboard->GetValueAsString(BlackboardKey.SelectedKeyName);

		DialogueArguments.Add(StringKey, FText::FromString(TextValue));

	}

};

And here is an example of integration in Question node.

BTComposite_Question.h :


FText GetQuestionThumbnail(UBehaviorTreeComponent& OwnerComp) const;

/** Question Parameters */
UPROPERTY(EditInstanceOnly, Category = Question)
TArray<FDialogueParameter> DialogueParameters;


BTComposite_Question.cpp :


FText UBTComposite_Question::GetQuestionThumbnail(UBehaviorTreeComponent& OwnerComp) const
{

	FFormatNamedArguments DialogueArguments;

	for (const FDialogueParameter& DialogueParameter : DialogueParameters)
		DialogueParameter.PushArgument(DialogueArguments, OwnerComp);

	return FText::Format(QuestionThumbnail, DialogueArguments);

}

You just have to compare the same generated text in the GetNextChildHandler function in the same file :


FText GetQuestion = GetQuestionThumbnail(SearchData.OwnerComp);
if (GetQuestion.ToString() == AnswerText.ToString())
{
	NextChildIdx = 0;
	AnswerNode->ClearAnswer();
}

And print it in the Execute_Task function in BTTask_WaitAnswer.cpp :


NewSampleTextBlock->SetText(FText::Format(NSLOCTEXT("DialogueSystem", "ButtonText", "{0}"), Question->GetQuestionThumbnail(OwnerComp)));

Give you something like this :

e870d00f87bdd32789e58d7a8fae8746efb30b78.jpeg