Skip to content

Using C++

This page provides some additional information that may be useful for scripting the commentary in C++.

Source overview

The SportsCommentary plugin comes with two modules in its Source folder:

  • Commentary – a runtime module with all commentary functionality. Important for scripting.
  • CommentaryUncooked – an UncookedOnly module with the MakeVoiceline K2Node. Not needed for scripting in C++.

The most important headers for scripting are CommentarySubsystem.h and VoicelineSequence.h. For specifying voicelines, you will also be working with Voiceline.h. And for extending functionality of the subtitle widget, SubtitleDisplay.h.

Names of functions and classes mentioned throughout this documentation generally correspond to the ones in C++, with the exception of prefixes such as UVoicelineSequence.

Common tasks in C++

Accessing the subsystem

GetWorld()->GetSubsystem<UCommentarySubsystem>();

Specifying voicelines

There is no “friendly node” in C++ but you may still construct a UVoiceline and set its Recipe property of type FVoicelineRecipe. It consists of the voiceline’s row name and a map with context for interchangeable content.

Enqueueing sequences

To make them readable for Blueprint users, both the SingleVoicelineSequence and MultiVoicelineSequence are made in Blueprint, thus unavailable in C++. They are both only a few commands long though, so if you would like to use them in C++, they are not difficult to replicate.

Custom sequences are enqueued just like in Blueprint (UCommentarySubsystem::EnqueueSequence).

Creating custom sequences

The same steps apply as on the Custom sequences page, with the only caveat that to implement the native events you need to override their _Implementation such as UVoicelineSequence::Setup_Implementation().

Keep in mind that the sequence only gets a reference to the world when initialised by the subsystem – calling GetWorld() before Setup returns nullptr.