Quickstart
Last updated
Last updated
To get started, make sure you've first installed the system, you can find details on that in Installation.
There are two things you can do to get started with this system;
Use the default Interaction Actor
Create your own Interaction Base actor.
Either option is completely valid to do and really depends on your needs. The Default Interaction Actor comes with the boiler plate setup to get started and will allow you set up a new interactable right away.
Head to your content folder, right click and click Blueprint Class. Then search for BP_BUIS_Interactable
choose this as your base class, name it whatever suits your needs. In my case I will be calling it BP_Interactable
. This will function as our new base class going forward, we can create all sorts of interactables from this class here, and be able to add some extra default logic to our Interactables going forward if we so desire, without changing the default functionality of the system itself.
Next we want to create another Subclass of the Interactable class we just made. We do this by right clicking the Class we just made and then click Create Child Blueprint Class
Let's name it BP_Switch
.
Open up BP_Switch and click the Interaction Component. Check the details panel and make sure that the Interaction Execution Mode has been set to Instant.
Now scroll the details panel down until you find the Events
section. Click the On Interaction Triggered Plus button. This will present you with an On Interaction Triggered Event in your Event Graph.
Add a Print String to this event, put in Switch Interacted With as its string property value.
Before we can interact with our new interactable, we'll need to set up an interaction manager. The interaction manager is what handles how the player interacts with an Interactable. You can find more information on Interaction Managers on the Player Interaction Manager page.
To create an interaction manager we need to create a new blueprint class. Go to the content browser, right click in an empty space and create another blueprint class. This time search for Interaction Manager and select the BP_BUIS_PlayerInteractionManager
.
I will call it BP_InteractionManager
.
Next open up the Interaction Manager you just created, then override the Get Trace Location function. You do this by heading to the Functions Category in the menu to the left, and hover over the category and then click the override dropdown button, and then search for the function.
This function allows us to determine where the start and end trace for detecting and interacting with them will start when we either do a Linetrace of a Sphere Trace.
Next create a float variable property and call it Length, this will be used to determine the trace length for interactables. Set the default value to 500.
Now you can set up the trace behavior. Mine looks like the screenshot below.
We now just need to set up our character to be able to interact with the interactable.
Create a new character, call it whatever you want to - I will simply just call it BP_PlayerCharacter.
Lets add the Interaction Manager we just created in the previous section. Click the Add button under components and find your Interaction Manager Component.
Next we want to set up a key input to be able to interact with our interactables. For simplicity sake we will simply add the Input Key Event E to the graph.
Then to your tick function add Detect Interactable
. This is required to be able to interact, and otherwise detect interactables.
With this you're ready to interact with your interactable.
You can now go test to see if it works by simply adding your created interactable from earlier to the level, and then walk up to it and press E, this should print out the string you set earlier.
Next head go into the Class Settings Menu and then in the details panel look under Implemented Interfaces, and add the BPI_BUIS_InteractionManagerInterface
.
You will now have one function underneath the Interfaces in the category to the left.
Get Player Interaction Manager Component: This will allow you to get the Player Interaction Manager Component easily from any entity. It is also required for the interaction system to work correctly with certain callback functions.
Open the Get Player Interaction Manager Component, and make sure you add your Interaction Manager to its return value.
Now what if you want the switch to be able to activate other actors remotely. Well - we can do this by creating a subclass of the BP_BUIS_Activatable
.
The BP_BUIS_Activatable
has already been set up with the required boilerplate code to allow for being activated.
Create a new Blueprint Class, make sure to search for the BP_BUIS_Activatable
.
Open up your new activatable class. Click the BP_BUIS_ActivationComponent
in the component list and then go to the events section in the details panel. Click On Activation and On Deactivation, this will allow us to react to any deactivation and activation event this actor will receive.
I am going to add a Point Light to the Activatable Actors Component list, and then I am going to set the light color to Red On Deactivation, and Green On Activation.
To activate our activatable we'll need to modify our switch a bit.
In our Switch interactable blueprint I'll add an Actor Reference property and call it Actor to Activate, and make it instance editable by clicking the little eye icon next to the property so the eye is open.
This will allow us to set the actor reference that we want to activate upon triggering this interactable.
Now we'll just need to trigger the Activatable upon triggering the interaction. To do this simply drag the Actor To Activate into the graph and then toggle its activation state like we are in the screenshot below.
Now that we're all set up, simply drag the Activatable actor into the level, make sure your activatable and Interactable has been properly compiled, and then select your Interactable, find the Actor To Activate property entry in its detail panel and assign the Activatable to it.
You should now see that pressing E on the Interactable will cause the light to switch from white to Green and then to Red if you interact with the Interactable again.