Tutorial¶
Introduction¶
This interaction system is designed to be flexible and easily extendable to handle any
common or game specific interaction.
In this tutorial we will learn how to create a simple door interaction then create
specific behaviors like adding requirements.
Create project¶
Create a new project based on Third person template
Install the plugin¶
Ensure the plugin is correctly installed and enabled
Collisions¶
Then we will need to configure collisions for physical interactions.
Create a New Trace Channel
named Interact
.
We set the default response to Ignore
so we can manually choose the actors that will
respond to our interactions
Tags¶
You can create new tags to organize actions and slots for your project or use existing ones.
For this example, we will create a primary action and a slot for our door lock.
Go to the gameplay tag manager and create two news tags:
- Interact.Action.Primary
that represents our main interact action (we will bind the input later)
- Interact.Slots.Lock
that physically represents our Lock
Info
See Concepts for more informations about Actions and Slots
Inputs¶
Now we need to create an input action and a mapping context for our interactions.
Create IA_Interact
and IMC_Interact
then bind the E
key to IA_Interact
Info
You can use a single mapping context but for a better architecture, we put our interaction inputs in a separated mapping context
Then we will map our interact actions to the input system.
Create a data asset using the class NIS Action Mapping Asset
named DA_InteractMapping
Name the action Interact
and set the created input action IA_Interact
Settings¶
Go to Project settings > Game > NIS Settings
- Set the default collision channel to Interact
- Set the action slot to Interact.Action.Primary
- Set the interact action mapping to DA_InteractMapping
Info
An action can bind to one or multiple slot. Here we have a simple configuration where our primary action will use the default slot. Those bindings can be configured per interact component for more complex configurations
Interactor (player)¶
To interact, we need an interactor (it could be a player or an AI).
Create a new PlayerController
blueprint named B_PlayerController
and set it in the game mode settings
Open it and add a new component, select NIS Player Interactor
Configure the player interactor to use the range scanner and set the input mapping context
we created (IMC_Interact
)
Interact (door)¶
Now that we have a player that can interact, we can create our door. We will need an interact component, a slot, and an indicator
Create a new blueprint named B_Door
- Create a mesh slot that will represent our door
- Configure its collision by selecting a mesh and check the
Interact
trace response after selectingCustom
inCollisions Presets
Info
We will see later how to configure slots to create advanced interactions
- Create an interact component to write the logic of our interaction, select
NIS Interact Instant
Info
The instant interact is a type of interaction that will end directly. See Architecture to understand the interaction process
The interact component has many events, add the OnInteract
event.
We make a simple code to open vertically the door and close it
Requirements¶
Now that we have a basic interaction, we will use the requirement system to unlock the door only if our player has a specific key.
First we store a KeyId variable in our B_PlayerController
Info
In a real game we would store those kind of variables in a better place
Then we store a KeyId for our B_Door
. Don't forget to set it Instance editable
so you
can change the KeyId of door instances in the world.
We create our KeyRequirement
to do so, create a new blueprint class inheriting from
NIS_RequirementBase
named B_KeyRequirement
A requirement has two implementable functions:
- Check
: returns true if the interactor meet the requirements
- GetText
: returns the text to display if the requirement failed
We write a Check function that will compare the KeyId of the door and the KeyId of the player to know if the player meet the requirements and can interact with the door.
To test what we have done:
- Set the player KeyId to 1
- Create one door A with a KeyId of 1
- Create one door B with a KeyId of 2
- Try to open both doors, only the door A will open
But we don't have any feedback when the door is locked. To add a message when a requirement fails,
that's very simple, just add the interact component event OnInteractRequirementsFailure
.
We only get the first element because we have only one requirement, but you could get all errors
if you use multiple requirements.