The Quest system is used to unlock various skills, provide experience/skill points and to progress through the game. Each quest can have multiple objectives and optionally include way points that will show up on the compass.
Objectives are modular and may be reused in any quest, for example, returning to a particular character after doing a task, or completing a previous objective. Objectives can be completed by performing specific tasks, which the objectives themselves will be monitoring, as they are blueprints with C++ base classes, they have all the required functionality of any other blueprints. Once all objectives are completed, the Quest itself is completed and any skill/experience points awarded.
Objectives include showing an information popup once the objective has spawned, so the player knows what the current objective is, but also it will update the journal and active quest UI, to indicate which objective is currently active. The below image is a test level, with test characters and a test Quest, with the first objective active.
The quests and objectives are blueprints and are spawned in game, and attached to the actor, this allows processes like checking for specific actors within a radius of the player quite simple, and once any is completed, they are detached and destroyed, and do not take up further processing.
Video Of Breakdown Here:
The C++ FGQuestActor is the base class for all quests and includes common properties like description, xp/skill awards, a list of objectives and then a reference and index to the currently active objective.
The BaseQuestBP blueprint which derives from FGQuestActor is the base blueprint for all Quest blueprints and contains common functions for all quests. From the BeginPlay it will ensure the current objective is spawned by calling the SpawnCurrentObjective blueprint function. It also handles the NextObjective event which can be called from C++/blueprint to complete the current objective, and spawn the next objective.
The BaseQuestBP SpawnCurrentObjective blueprint function, is responsible for Spawning the current objective, by using the current objective index and attaching it to the quest itself.
The FGQuestActor CurrentObjectiveCompleted C++ function, is called from either C++ or blueprint, and will complete the current objective by destroying it, and if there are more objectives, will call the NextObjective blueprint event, or it will call the QuestCompleted blueprint event.
The C++ FGObjectiveActor is the base class for all objective actors and contains common properties like the description, a reference to the QuestActor is belongs to as well as an optional 3D Vector way point that will show up on the compass of the player UI.
BaseObjectiveBP which derives from the C++ FGObjectiveActor is the blueprint all objective blueprints derive from, and contains some common functionality. From the BeginPlay ( meaning once the objective is active, either from loading a game, or by receiving a new objective ) it will popup an information message once, to indicate whatever the description contains. Objectives may also optionally have experience/skill points awarded on completion, but that is more rare, and they are generally awarded after the quest is completed.
Quests can be provided by interacting with an AI by talking about specific topics, these are dynamically linked by the conversation system by calling the C++ MakeQuestActive function, which resides in the FishGibbleUE4Character C++ class, which is the base class for all characters, including AI.
Quests are also spawned from the LoadGame C++ function, also in the character class, this is called when a saved game is loaded and the character was in the middle of a quest. This also calls the MakeQuestActive C++ function.
The FishGibbleUE4Chacater MakeQuestActive C++ function is responsible for setting up and invoking the SpawnActiveQuest blueprint event. This will ensure that the actual spawning takes place in blueprint, and not in C++, which is far more preferable, and allows for a very robust and interoperable quest spawning system, which can be called from either C++ or blueprints.
The SpawnActiveQuest blueprint event is handled in the ThirdPersonCharacter blueprint class, which is the base blueprint for all characters and AI in the game and will then invoke the SpawnQuestFunc blueprint function.
This function is responsible for ensuring the quest class exists within the game mode ( so it is a valid quest name ), and then spawns the quest, and attaches it to the actor. The quest BeginPlay will then call the spawn current objective function, which will then spawn the current objective, and attach it to the quest.
Master Catfish Test Quest
A practical quest, that unlocks a few skills, and serves as a bit of a tutorial. Keeping in mind these are all test character meshes, including the level itself.
The MasterCatfishQuest consists of 12 objectives.
Take Damage Objective
The MCQ_01_TakeDamageBP is the first objective. It shows a waypoint to the closest enemy character by calling the TrackClosestEnemyFish blueprint function, and once the player’s health has fallen below 75% of it’s maximum, the objective will complete itself by calling the CurrentObjectiveCompleted blueprint function, on the QuestActor the objective belongs to , and then the next objective will become active.
The TrackClosestEnemyFish blueprint function, tracks the closest, hunting AI and sets the waypoint to that character ( if any ).
Return To Master Catfish Objective
The MCQ_02_ReturnToMCBP blueprint objective is reused in this quest, every time the player completed a task, and needs to return to the quest giver. Form the BeginPlay ( when the objective is spawned ) a reference to the skill teacher is cached, then from the tick event if the player is further than 100 units away from the teacher, a way point is shown towards the skill teacher.
This objective does not complete by itself, a specific topic needs to be selected from dynamic conversation system, then this objective will complete, and the next one will be given.
Shooting Enemy AI Objective
The MCQ_06_ShootingBP objective tracks player kills, and completes when the player has killed more than 2 enemy AI, it will also track and show a way point to an ammo cache.
Every 30 seconds a popup will appear that plays an animation on the player HUD, showing how many kills left to go.
This is done by calling the ShowCountdownPopup blueprint function from the player character.
Which in turn gets a reference to the CountdownHUD which is an overlay, with some animation, and calls the SetCountDownImage blueprint function on the HUD itself, which will setup and call the PopupCountdown UI animation.
The MCQ_06_ShootingBP PopupPlayerInfo blueprint function is called every few seconds to help the player unlock shooting, if it has not been unlocked already, or to guide the player on how to aim and shoot. This can further be refined to only show the message until a shot has been fired for example.
The SetPlayerUnlockable blueprint function is called to ensure the Shooting skill is unlocked, so that the skill system will allow it to be unlocked from the skill UI, by spending skill points. This way, skills are controlled bvy the game, when they may be unlocked from the skills system.