Examples
To exemplify the previous base classes, the following guide will create 3 actors;Â
a button: player interacts directly with this actor (this actor could also be a door that opens immediately, or an animated switch, for example)
an overlap: player overlaps this actor which then interacts with another actor
a respondent light: an interactable directly interacts with this actor (this could also be a door that opens from a button, etc)
There are 4 ways to interact with an actor.Â
Button
This button will inherit from BP_InteractableOverlapBase so that we can control when this button is allowed to be pressed. But you are free to inherit directly from BP_InteractableBase if you just want the button to be interacted with by TraceOnly
Set the Type to OverlapInteract
Also ShowHintText to True
Add a StaticMesh component to the components window and call it ButtonMesh
Set the ButtonMesh to SM_ButtonStand
Move the proxy in front of the button mesh
Create a MID on the construction script from the ButtonMesh
Call the OnActiveRelevance delegate from the component. This fires when the actor is relevant
When this button is pressed, the switch aesthetics will remain on/off to others when it matters to them
If you want this button to do something immediately, call OnInteract. This button is fairly simple so we just want to make sure others see the relevant changes. You might perform some animations on a switch here, for example.Â
Overlap
We will now inherit a new actor from BP_InteractableOverlapBase and call it BP_InteractableOverlap. This will be a world actor that can be used to communicate with other interactable respondents in the Level
Open BP_InteractableOverlap and add a Billboard component. This will make it easier to see and move around in the world.
Add an event from the component OnActorOverlapped
Call ActivatorInteract
Respondent
This actor will inherit from BP_InteractableRespondentBase and will be called BP_InteractableRespondentLight. This will react to the overlap or the button when we place it into the world
Open the blueprint and add a static mesh component called LightMesh
Set the LightMesh as SM_LightBulb
Add a PointLight component as a child to LightMesh
Move it up a bit on the Z-axis to be more centred to the mesh glass
Set the light color to black
Create a MID for each element on the Construction Script
Create a function called UpdateLight
Call OnRespondentInteract on the component
SelectColor from the NewColor of UpdateLight and on (A) make the colour white, and for (B) leave it black, which is "off"
Clickable
This actor will inherit from BP_InteractableOverlapBase and will accept incoming clicks from the Player Controller
Base
First, make sure BP_InteractableBase has the Clickable parameter created and constructed. Make this parameter InstanceEditable
Player Controller
Create a player controller, Call it BP_PlayerController
In its Class Defaults, enable Click Events
Create this logic on the event graph so that we can see the mouse cursor and control the actor with clicks
Game Mode
Define the new player controller in BP_ThirdPersonGameMode
Interactable (Base and Child)
Create a base clickable actor that inherits from BP_InteractableOverlapBase and call it BP_InteractableClickableBase. From the Clickable Base, create a new child called BP_InteractableClickableButton and move it into the Interactables folder
Open BP_InteractableClickableBase and call ServerClickInteract off the controller's controlled pawn with a pointer to the interact component on BeginPlay
And flag Clickable and ShowHintText to True
Open BP_InteractableClickableButton and add a static mesh with the button stand mesh
We want to make sure that we are overlapping this actor before we can allow click events, so change the Type to OverlapInteract
Create a MID on the Construction Script
Call OnActiveRelevance on the construction script and set the scalar parameter of the State value
Add the Clickable Button to the Light's Activators list, and PIE for test. You should now be able to click the clickable button when in the overlap volume, to turn on the light