The MidiEngine 3 Plugin for Unreal Engine 5 includes templates for developing note highway rhythm games like Guitar Hero, Fortnite Festival, and similar titles. In this tutorial, we’ll dive deep into these templates. Make sure you’ve installed the MidiEngine 3 Plugin or its demo version. You can find the NoteHighway templates in the “RhythmTools_Content” folder within the plugin.
Rhythm Sections
Navigate to “RhythmTools_Content/Blueprints/Actors” and open the “BP_2DRhythmSectionActor” to follow along.
A RhythmSectionComponent is a specialized type of MIDI Listener Component. As detailed in the Getting Started section of MidiEngine 3, this component extends the functionality of the UAxMidiListenerComponent. The RhythmSection is designed to detect MIDI events and generate Rhythm Actors, which travel along Rhythm Splines towards a designated judgement area.
/**
* @brief A RhythmSection Listens for MidiEvents and spawns Rhythm Actors that move along Rhythm Splines in a timely manner.
* NB: The Actor that uses this Component MUST implement the RhythmSection Interface and the functions for that interface.
* Specifically: this component will call SelectRhythmSpline() and SpawnRhythmActor() from the interface on MidiNoteOn.
*
*/
UCLASS(ClassGroup = ("MidiEngine"), meta = (BlueprintSpawnableComponent))
class AXMIDIENGINECORE_API URhythmSectionComponent : public UAxMidiListenerComponent
What's A RhythmActor?
A RhythmActor is an actor that visually represents a MIDI note on the RhythmSection or NoteHighway. To be recognized as a RhythmActor, any AActor must implement the RhythmInputInterface and override the SetRhythmInput
and GetRhythmInput
functions.
Rhythm Input Interface
A RhythmActor must define or be assigned an InputAction that the player needs to match to score points. For instance, you might associate a spawned RhythmActor with the “D” key, requiring the player to press “D” when the RhythmActor reaches the JudgementArea to score points.
Get Rhythm Input Function
The idea here is the system will call this function whenever the Actor reaches the judgement area and the returned InputAction will be checked against the Player’s Input in order to award him a score.
You can create a variable to store the required Input in the Rhythm Actor’s blueprint/class.
What's A Judgement Area?
In the context of note highway rhythm games, a Judgement Area is a critical zone where the player’s input is evaluated. As Rhythm Actors, which represent musical notes or beats, move along the Rhythm Splines, they approach the Judgement Area. The player’s timing and accuracy in hitting the notes are assessed in this zone. Depending on how precisely the player matches the Rhythm Actor’s position in the Judgement Area, they receive a score or feedback indicating their performance (e.g., Perfect, Good, Miss). The Judgement Area is essential for providing real-time feedback and scoring, making it a core element of the gameplay experience.
Judgement Point Index
The RhythmSection Component lets you define one of the Points in a Spline as the Judgment Point. As Rhythm Actors move along the spline, their target is to reach this Point in X time.
Rhythm Judgement Box
The Rhythm Judgement Box is a specialized BoxCollisionComponent that tracks RhythmActors as they pass through it. Here’s how to use it:
- Placement: Place the Rhythm Judgement Box around the Judgement Point of the spline.
- Function: While a RhythmActor is traveling along the spline, its target is to reach the Judgement Point at a specific time.
- Coverage: The Judgement Point should be surrounded by the Rhythm Judgement Box to ensure it accurately tracks the RhythmActors reaching the Judgement Area.
Rhythm Section Actors
In Unreal Engine, an actor is a UObject that can be placed in the game world. A RhythmSectionActor, specifically, is an actor that includes the “RhythmSectionComponent” and implements the RhythmSection Interface. By adding this interface to any actor, you enable it to be recognized by the MidiEngine system as a RhythmSectionActor. This means it can listen for MIDI events and react appropriately, integrating seamlessly with the MIDI-based rhythm game mechanics.
If you’re not familiar with interfaces in Unreal Engine, you can add one by navigating to “Class Settings” and then adding the interface under “Implemented Interfaces.”
To qualify as a RhythmSectionActor, your actor must have a RhythmSectionComponent and implement the RhythmSectionInterface. These are the two essential requirements for an actor to be recognized by the MidiEngine system as a RhythmSectionActor.
Rhythm Section Interface
By adding the RhythmSectionInterface, you’ll gain access to two functions that you must override and define: SpawnRhythmActor
and SelectRhythmSpline
. These functions are crucial for the actor’s interaction with the MIDI system, allowing it to spawn Rhythm Actors and determine the appropriate Rhythm Splines for them to follow.
Select Rhythm Spline Function
The SelectRhythmSpline
function is called when a MIDI note is activated (MidiNoteOn). In this function, you’re expected to determine which spline the RhythmActor for the note should spawn on and follow and then return that spline. This function gives you the flexibility to decide where each note goes by analyzing its details, such as the MIDI track it belongs to and its pitch.
You have complete freedom and flexibility to chose which notes go on which note highways using this function. Once you’ve written that logic return the chosen spline.
Spawn Rhythm Actor Function
Once you’ve selected the spline, the system will allow you to spawn a Rhythm Actor to visually represent the playing note. You need to:
- Spawn an actor.
- Set up its properties, especially the required rhythm input for scoring.
- Return the newly spawned actor to the system.
The system will then handle moving the actor along the spline and ensuring it reaches the Judgement Area on time. This function also provides the spline as an argument, so you can use its details to decide the input for the Rhythm Actor if needed.
Handling User Input And Awarding Score
Here’s how you handle user input and determine the score:
User Presses a Button:
- The system detects the button press.
Check for RhythmActor in Judgement Area:
- The system checks if any RhythmActor (MIDI note) is currently in the NoteHighway’s Judgement Area (Collision Box).
Match Input Action:
- If a RhythmActor is in the Judgement Area, check if the stored Input Action for that RhythmActor matches the button the user pressed.
Award Score:
- If the Input Action matches, award the user a score.
Optional – Refine Scoring:
- Add logic to give different scores based on how early or late the player presses the button, depending on the RhythmActor’s position within the Judgement Area. This allows for more precise scoring based on the timing of the player’s input
Recreating Fortnite Festival With The MidiEngine Plugin
You can watch this playlist which showcases how you can make something similar to Fortnite Festival using MidiEngine 3.