Quest Events are how you execute custom logic when the state of a quest changes. Included in this project you will find an example to spawn, and destroy an actor in the world, as well as play cutscene example. I also include the framing to give an item to the player (like a quest item) for you to easily integrate into your own item system.
Each Quest has the ability to set any number of quest events using the onStateChange variable on the data table. You can also pass data to your events using the optional QuestStateData field (string to string map), this lets you create dynamic events that can be customized or controlled by your quest states.
How to make a Quest Event
- Create a child of the BP_QuestEvents blueprint found in the Blueprints/QuestEvents folder for your new event and give it a name.
- Open your new child blueprint up then override the HandleEvent event. This event will provide you with your QuestStateData, the Controller, the QuestRowName, and the new QuestState.
Re-running Events OnLoad
Sometimes you may need to rerun an event on begin play. For example, let's say when the player accepted a quest a door in your level opened, but then the player decided to quit your game and come back later. When they start back up that next session they are going to expect that door to still be opened.
By default it will not be opened, but to make the event run again all you need to do is add a new key to the QuestStateData for your event called onload. It does not need a value.
On Begin Play if my system detects this in one of your state events for the current state of the quest it will know to run it again. Keep in mind this will not rerun logic from previous states of the quest.
Undoing Events on Drop Quest
As you can see, quest events give you a lot of flexibility with how the quest system can integrate into your game, but there is one more important thing to keep in mind, and that is the player will always have the option to drop a quest.
When this happens you might want to change what happens in your level. Remember that door we opened for the player in the last section when they accepted the quest? Now that they dropped the quest, that door should probably be closed.
We handle these “undo” type events through the onDropQuest field on our Quest data table. This variable lets you add Quest Events to run if the player drops the quest.
Included Quest Events
Give Items to Player (BP_QuestEvents_GiveItems)
This event gives you a jump off point to give items to your player through your inventory and item system. The QuestStateData is used as a list of items, and their quantities. In the key for each row enter the ItemRowName as it appears in your inventory system, then for the value you are going to want to set your quantity as an integer.
You are going to need to connect this function to your item system before it will work. Take a look at the custom integration section of the Quest Rewards for a full list of all functions requiring edits to work with your inventory / item system.
Play Cutscene (BP_QuestEvents_PlayCutscene)
If you would like to play a Level Sequence (Cutscene) for the player when the state changes this is the event you will want to use. This event is expecting the key cutscene in your QuestStateData variable. The value for cutscene should be a tag that is also set on your Level Sequence actor in your level.
Spawn Button Example (BP_QuestEvents_SpawnButton)
I have also included a simple example of spawning an actor in your level when the quest state changes. This is what is used to spawn the button that appears next to the repeatable quest giver in my demo world when you accept the quest. The onload key added to the QuestStateData is how we know to respawn this button when the game restarts (if the quest is still in the current state).
Destroy Button Example (BP_QuestEvents_DestroyButton)
When you turn in the repeatable quest in my demo world this is how the button is removed from the level. This is also used on the onDropQuest variable to handle removing the button from the level when the player drops the quest from the Quest Log UI.