Neocortex Logo
Use ChatGPT in Unreal Engine Blueprints: call the OpenAI API from a C++ node, expose it to Blueprints, and compare it with a voiced NPC from the Neocortex plugin.

How to Use ChatGPT in Unreal Engine Blueprints

TutorialUnreal EngineAI NPC

"How do I use ChatGPT in Unreal Blueprints?" usually means: let players talk to an NPC and have a language model answer. Unreal has no Blueprint node for web requests, so the first step is a little C++. This guide builds a Blueprint-callable ChatGPT node with Unreal's HTTP module, then shows what it takes to ship and how the same NPC looks with the Neocortex plugin.

Route 1: a ChatGPT node for Blueprints

You need a C++ project, an OpenAI API key, and the HTTP and Json modules added to PublicDependencyModuleNames in your Build.cs. This component sends one player line to the chat completions endpoint and raises a Blueprint event with the answer:

// NpcChatComponent.cpp: declare Ask as a BlueprintCallable UFUNCTION and OnReply as a
// BlueprintAssignable delegate with one FString parameter in NpcChatComponent.h
#include "NpcChatComponent.h"
#include "HttpModule.h"
#include "Interfaces/IHttpResponse.h"
#include "Dom/JsonObject.h"
#include "Serialization/JsonReader.h"
#include "Serialization/JsonSerializer.h"

static TSharedPtr<FJsonValue> ChatMessage(const FString& Role, const FString& Content)
{
    TSharedRef<FJsonObject> Message = MakeShared<FJsonObject>();
    Message->SetStringField(TEXT("role"), Role);
    Message->SetStringField(TEXT("content"), Content);
    return MakeShared<FJsonValueObject>(Message);
}

void UNpcChatComponent::Ask(const FString& PlayerLine)
{
    TSharedRef<FJsonObject> Root = MakeShared<FJsonObject>();
    Root->SetStringField(TEXT("model"), TEXT("MODEL_NAME"));
    Root->SetArrayField(TEXT("messages"), { ChatMessage(TEXT("system"), SystemPrompt), ChatMessage(TEXT("user"), PlayerLine) });
    FString Body;
    FJsonSerializer::Serialize(Root, TJsonWriterFactory<>::Create(&Body));

    TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = FHttpModule::Get().CreateRequest();
    Request->SetURL(TEXT("https://api.openai.com/v1/chat/completions"));
    Request->SetVerb(TEXT("POST"));
    Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
    Request->SetHeader(TEXT("Authorization"), TEXT("Bearer ") + ApiKey); // testing only, never ship it
    Request->SetContentAsString(Body);
    Request->OnProcessRequestComplete().BindWeakLambda(this, [this](FHttpRequestPtr, FHttpResponsePtr Response, bool bOk)
    {
        TSharedPtr<FJsonObject> Json;
        if (!bOk || !Response.IsValid() || !FJsonSerializer::Deserialize(TJsonReaderFactory<>::Create(Response->GetContentAsString()), Json)) return;
        const TArray<TSharedPtr<FJsonValue>>* Choices;
        if (Json->TryGetArrayField(TEXT("choices"), Choices) && Choices->Num() > 0)
        {
            OnReply.Broadcast((*Choices)[0]->AsObject()->GetObjectField(TEXT("message"))->GetStringField(TEXT("content")));
        }
    });
    Request->ProcessRequest();
}

Add the component to your NPC, set SystemPrompt ("You are Brannoch, a gruff blacksmith...") and the key, and in Blueprints call Ask and bind On Reply to your dialogue widget. Replace MODEL_NAME with a current model from OpenAI's docs. The response arrives on the game thread, so it's safe to update UI from the event.

This sends one line at a time. For a conversation, keep an array of messages and send all of them with each request.

What it leaves you to build

  • The key. A key packaged with the game can be extracted and spends your whole OpenAI account. You need your own server between the game and the API.
  • Voice. Speech-to-text for the player, text-to-speech for the reply, decoding the audio into a Sound Wave, and keeping the wait short. See how the AI NPC voice pipeline works.
  • Emotion and actions. The reply is plain text. To drive animation and gameplay you prompt for JSON and parse it, then handle the times it's malformed.
  • History and cost. Every message makes the next request bigger, slower and pricier.
  • Staying in character. Players will try to break a system prompt within minutes. See how to keep AI NPCs in character.

Route 2: the same NPC with the Neocortex plugin

With Neocortex, the character is designed in a browser editor, with a personality, a world, a knowledge base, a voice and actions, and the Unreal plugin gives you Blueprint nodes for the rest:

  1. Clone the plugin into your project's Plugins folder, enable it, and add "Neocortex" to your Build.cs.
  2. Paste your API key in Project Settings > Game > Neocortex.
  3. Add a Neocortex Smart Agent component to the NPC and set its Project Id.
  4. Call Send Message For Audio with the player's line.
  5. Bind On Chat for the text, emotion and action, and On Audio for a Sound Wave you play with Set Sound and Play.

For voice input, the Neocortex Microphone Recorder component records and transcribes the player, so a push-to-talk button is three Blueprint nodes. The full walkthrough is in how to add AI NPCs to Unreal Engine 5.

Side by side

OpenAI API from C++Neocortex Unreal plugin
First replyA C++ component and JSON parsingBlueprint nodes
Voice in and outBuild it yourselfRecorder component, Sound Wave out
EmotionPrompt and parseOn every reply
ActionsPrompt for JSON and validateDefined in the editor, sent as a keyword
Conversation historyYour array, growingKept in a session per character
Key protectionYour own serverPer-player and per-character limits on each key
Character designA system promptVisual editor with free testing

Common questions on the do-it-yourself route

  • "The request never returns." Check the HTTP module is in your Build.cs and that the request isn't garbage collected: keep the call inside a component that lives as long as the NPC.
  • "The JSON breaks on quotes." Build the body with FJsonObject, as above, instead of formatting strings by hand. Players type apostrophes and quotes all the time.
  • "Can I call it from Blueprint-only projects?" Not without C++ or a third-party HTTP plugin.

Next steps

For the design side, read how to give NPCs unique personalities and how to make AI NPCs act on what they say. Every tutorial is in the guide to building AI NPCs.

Checked November 2026. Neocortex is not affiliated with OpenAI or Epic Games.

Frequently Asked Questions

Can I use ChatGPT in Unreal Engine Blueprints?

Not with built-in nodes. Unreal has no Blueprint node for HTTP requests, so you write a small C++ function with the HTTP module and expose it to Blueprints, or install a plugin. The Neocortex plugin gives you a full AI character with Blueprint nodes and voice.

Do I need C++ to call an LLM from Unreal?

For a direct API call, a few lines of C++ or a third-party HTTP plugin. With Neocortex the project must be a C++ project so the plugin compiles, but everything you use is a Blueprint node.

Is it safe to put an OpenAI API key in an Unreal game?

No. Anything packaged with the game can be extracted, and an OpenAI key gives full access to your account's spending. Route calls through your own server. Neocortex keys can carry per-player and per-character usage limits that our servers enforce, and you can deactivate a key from the dashboard.

How do I give a ChatGPT NPC a voice in Unreal?

You'd add speech-to-text for the player and text-to-speech for the reply, then turn the audio into a Sound Wave. The Neocortex plugin returns the reply as a Sound Wave you can play, and records and transcribes the player's voice.

Written by

Sercan Altundas

Date

Nov 19, 2026

Read time

9 min

Similar Posts