PlayKit.ai

Text Generation

Generate AI-powered text responses in Unreal Engine

Text Generation

UPlayKitChatClient is an Actor Component for AI text generation. Add it to any Actor in the editor, configure it in the Details panel, bind to its events, and call GenerateText().

Setup

Blueprint

  1. Select your Actor and click Add Component → search for PlayKit Chat Client
  2. In the Details panel, set System Prompt and optionally adjust Model Name and Temperature
  3. Click + next to On Chat Response to bind a response handler

C++

Add the component to your Actor and bind events in BeginPlay:

#include "Client/PlayKitChatClient.h"

UCLASS()
class AMyActor : public AActor
{
    GENERATED_BODY()

    UPROPERTY(VisibleAnywhere)
    UPlayKitChatClient* ChatClient;

    virtual void BeginPlay() override;

    UFUNCTION()
    void HandleChatResponse(const FPlayKitChatResponse& Response);
};

void AMyActor::BeginPlay()
{
    Super::BeginPlay();
    ChatClient = FindComponentByClass<UPlayKitChatClient>();
    ChatClient->SystemPrompt = TEXT("You are a wise wizard named Merlin.");
    ChatClient->OnChatResponse.AddDynamic(this, &AMyActor::HandleChatResponse);
    ChatClient->OnError.AddDynamic(this, &AMyActor::HandleError);
}

void AMyActor::HandleChatResponse(const FPlayKitChatResponse& Response)
{
    if (Response.bSuccess)
        UE_LOG(LogTemp, Log, TEXT("Response: %s"), *Response.Content);
}

Basic Text Generation

ChatClient->GenerateText(TEXT("Tell me about dragons"));

The SystemPrompt property on the component sets the AI's personality for all requests. You can also change it at runtime:

ChatClient->SystemPrompt = TEXT("You are a fantasy loremaster.");
ChatClient->GenerateText(TEXT("What ancient secrets do you know?"));

Streaming Responses

Receive text in real-time as it generates, ideal for typewriter effects.

Blueprint

Bind On Stream Chunk and On Stream Complete events, then call Generate Text Stream.

C++

void AMyActor::BeginPlay()
{
    Super::BeginPlay();
    ChatClient = FindComponentByClass<UPlayKitChatClient>();
    ChatClient->OnStreamChunk.AddDynamic(this, &AMyActor::HandleChunk);
    ChatClient->OnStreamComplete.AddDynamic(this, &AMyActor::HandleComplete);
}

void AMyActor::HandleChunk(const FString& Chunk)
{
    DialogueWidget->AppendText(Chunk);
}

void AMyActor::StartStream()
{
    ChatClient->GenerateTextStream(TEXT("Write a short story about a knight"));
}

Advanced Configuration

For full control over messages and settings, use GenerateTextAdvanced():

FPlayKitChatConfig Config;
Config.Messages.Add({ TEXT("system"), TEXT("You are a game master.") });
Config.Messages.Add({ TEXT("user"), TEXT("What quest awaits me?") });
Config.Temperature = 0.9f;
Config.MaxTokens = 200;

ChatClient->GenerateTextAdvanced(Config);

Configuration Properties

PropertyTypeDefaultDescription
ModelNameFString"default-chat"AI model to use
Temperaturefloat0.7Response randomness (0.0–2.0)
MaxTokensint320Max tokens to generate (0 = no limit)
SystemPromptFStringDefault system prompt

Runtime setters: SetModelName(), SetTemperature().

Events

EventParametersDescription
OnChatResponseFPlayKitChatResponse ResponseFired when non-streaming response is received
OnStreamChunkFString ChunkFired for each chunk during streaming
OnStreamCompleteFString FullContentFired when streaming finishes
OnErrorFString ErrorCode, FString ErrorMessageFired on request failure

Multi-turn Conversations

UPlayKitChatClient is stateless — it does not maintain history between calls. For NPCs that remember conversation context, use UPlayKitNPCClient instead. See NPC Conversations.

Next Steps