Neocortex
IntegrationsUnity SDK

Quiz

Run a spoken quiz, game show or test in Unity with a Neocortex AI character as the host, for one player or several, using the Quiz Agent and a question set.

Team plan

Quizzes need a Team plan and at least one question set.

NeocortexQuizAgent lets one of your characters host a quiz, a game show or a spoken test. You write the questions in a question set on the web platform. Question order, retries, hints, judging and scoring happen on the server. Your game hands over what the player said and shows what comes back.

How a run works on the server is covered in Web API Quiz.

Quiz Show sample

Setting up

  • Add a NeocortexQuizAgent to the host's GameObject
  • Pick the host in its Character dropdown and the set in its Question Set dropdown. Both lists come from your account.
  • Optional: set Question Count (0 uses the set's own count) and Question Order (SetDefault, InOrder or Shuffled)

Neocortex Quiz Agent component

The host speaks in the character's voice. Turn off Speak Host Lines for a silent host. An AudioSource is added for the voice when you don't assign one. Add a NeocortexFaceAnimator on the host and its mouth follows each line.

For a quick text UI, add a NeocortexQuizUI with a chat panel, a text input and a thinking indicator. The input only shows while the host is waiting for an answer.

Running a quiz

QuizScene.cs
using UnityEngine;
using Neocortex;
using Neocortex.Data;

public class QuizScene : MonoBehaviour
{
    [SerializeField] private NeocortexQuizAgent quiz;

    private void Start()
    {
        quiz.OnHostLine.AddListener(line => subtitles.Show(line.text));
        quiz.OnQuestionChanged.AddListener(ShowQuestion);
        quiz.OnUpcomingQuestion.AddListener(next => scenery.Preload(next.keyword));
        quiz.OnLeaderboardChanged.AddListener(scoreboard.Show);
        quiz.OnQuizFinished.AddListener(results.Show);
        quiz.Begin();
    }

    private void ShowQuestion(QuizQuestion question)
    {
        questionLabel.text = question.questionText;
        scenery.Show(question.keyword);
        foreach (QuizOption option in question.options)
        {
            AddButton(option.text, () => quiz.Choose(option.id));
        }
    }
}

Begin() starts the run. The host welcomes the player and asks the first question. After that your game only reports what the player did:

Player didCall
Tapped an optionChoose(optionId)
SpokeSay(transcript)
TypedSay(text, true)
Skipped, or your timer ran outPass()

Hints, repeats and stopping are just words: Say("Can I have a hint?"). LastIntent tells you how the host read the last thing said, for example Hint or Repeat. A typed answer is judged as written, so a misspelling is not treated as a mishearing.

OnQuestionChanged fires as the host starts asking the question, so the scene changes on the right line. OnUpcomingQuestion gives the next question's keyword early, so you can load its scene while the host is still talking.

The question

QuizQuestion carries what the game may show, and nothing it may not: the answer, the rubric and the hint text stay on the server.

MemberDescription
questionTextThe question.
type"free_text", "multiple_choice" or "true_false".
optionsThe choices to show, each with id and text. Empty for an open answer.
IsChoiceTrue when the player picks from options.
keywordThe author's name for the scene this question needs, such as SHOW_RED_APPLE.
hasHintWhether the player can ask for a clue.

Voice answers

Open the microphone when the host expects something, transcribe the recording, and pass the text to Say():

Voice answers
private readonly ApiRequest api = new();

private void Start()
{
    quiz.OnExpectingChanged.AddListener(expecting =>
    {
        if (expecting != QuizExpecting.Nothing) mic.StartMicrophone();
    });
    mic.OnAudioRecorded.AddListener(OnRecorded);
}

private async void OnRecorded(AudioClip clip)
{
    string text = await api.RequestTranscription(quiz.characterID, clip);
    if (string.IsNullOrWhiteSpace(text)) mic.StartMicrophone(); // nothing heard, listen again
    else quiz.Say(text);
}

Expecting is Answer for an attempt at the question, Confirmation for a yes or a no (usually to an offer of another try), and Nothing while the host is talking or the quiz is over.

Don't send an empty transcript with Say(""). An empty string is a deliberate pass, which means the player chose to skip.

Several players

Fill Participants in the inspector, or pass a roster to Begin(), and name the player on each answer:

Several players
quiz.Begin(new[]
{
    new QuizParticipant { id = "anna", displayName = "Anna" },
    new QuizParticipant { id = "ben", displayName = "Ben" },
});

quiz.ChooseAs("anna", optionId);
quiz.SayAs("ben", transcript);
quiz.PassAs("ben"); // Ben's timer ran out

The host waits until everyone has answered. OnPendingChanged and PendingParticipants track who is still to answer, and AnsweredParticipants who has. Timers are yours. The Quiz Show sample runs one to four players.

OnResult raises how each player's answer was judged (participantId, verdict, score), and OnLeaderboardChanged the standings (participantId, displayName, totalScore, rank). Players on the same score share a rank.

Input while the host is busy

While a turn is in flight, IsBusy is true and OnBusyChanged fires. With Queue Input While Busy on (the default), what the player says is held and sent once the host is ready. Only the newest answer per player is kept, and an answer older than Max Pending Input Age (default 4 seconds) is dropped.

OnInputDropped(text, reason) tells you when something never reached the host:

ReasonWhy
SupersededThe player said something newer, which is sent instead.
ExpiredIt waited too long to still answer what the host asked.
FinishedThe run has already ended.
NoSessionThe quiz has not started yet.
FailedThe turn it would have gone on failed.
BusyThe host was busy and Queue Input While Busy is off.

Errors and recovery

When a turn fails, the agent drops held input and calls Resync() by itself, which reads the run back from the server and reopens input where it left off. Call Resync() yourself after a lost connection.

When your team has run out of usage, or a usage limit is reached, the agent raises OnCreditsExhausted(code) and keeps input closed until you call Resync().

Abort() silences the host and abandons whatever is in flight, without ending the run on the server.

The full list of members and events is in the API Reference.

On this page