NsInteraction lets an actor, usually the player, use other actors: doors, levers, pickups, and buttons. A sensor gives the targets. The interaction component asks each target for its option, keeps the best one, and runs it on a press or at the end of a hold.
NsInteraction has no UI and no input binding. Your game shows the prompt and calls the component from its input. NsInteraction depends on no other plugin.
NsInteraction folder into the Plugins folder of your project."NsInteraction" to the dependencies of your game module in Build.cs.The plugin has no project settings.
NsInteractableActor. Name it BP_Button.BP_Button and set a mesh. Its collision must block the Visibility channel.On Interact and add a Print String node.BP_Button in the level.Begin Interact on the Ns Interaction component when the input starts.End Interact when the input ends.In C++, implement INsInteractable on any actor:
// MyLever.h
#include "GameFramework/Actor.h"
#include "NsInteractable.h"
#include "MyLever.generated.h"
UCLASS()
class AMyLever : public AActor, public INsInteractable
{
GENERATED_BODY()
public:
virtual bool GetInteractionOption_Implementation(AActor* Interactor, UPrimitiveComponent* Part, FNsInteractionOption& OutOption) override
{
OutOption.Prompt = NSLOCTEXT("MyGame", "PullLever", "Pull the lever");
return true;
}
virtual bool ExecuteInteraction_Implementation(AActor* Interactor, const FNsInteractionOption& Option) override
{
bPulled = !bPulled;
return true;
}
bool bPulled = false;
};
NsInteractableActor.On Interact, or bind On Interacted.The default option has Action Id Use, Prompt “Use”, and Authority Server. To turn the option on or off in play, call Set Interaction Enabled.
NsInteractable.Get Interaction Option. Set the fields of Out Option and return true.Execute Interaction. Read Action Id from the option and run the action.On Interactor Enter and On Interactor Exit to react when an interactor starts or stops to consider the actor.Return false from Get Interaction Option when the part has no action now. Do not change game state in it, because the component calls it often.
Set View Source with another scene component.The sensor uses the first camera of the owner and the first Ns Interaction component of the owner. It traces each frame on the machine that controls the pawn.
On Component Begin Overlap event, call Handle Sensor Begin Overlap on the Ns Interaction component. Pass all pins.On Component End Overlap event, call Handle Sensor End Overlap the same way.In C++, bind the overlap delegates to UNsInteractionComponent::HandleSensorBeginOverlap and HandleSensorEndOverlap with AddDynamic.
Add Target with an actor and an optional part.Remove Target with the actor to remove all of its targets.Set Targets to replace the full list. The first target wins a tie.On Option Changed on the Ns Interaction component.Get Hold Progress each frame. It goes from 0 to 1.Hold.The action runs when the hold time ends. A release before the end runs the tap action, when it is set. The hold stops when the target changes.
Get Interaction Option. The Part input names the part that the sensor found.Execute Interaction, run the action that Action Id names.The prompt shows, and the input runs nothing.
Server.On a client, the component fires On Server Request and sends the request to the server. The server builds the option again and runs it when the option is enabled and names the same action. The pawn must belong to the player controller of the client.
To send the request yourself, clear Send Server Requests. Bind On Server Request, send the target and the action in your own server RPC, and call Execute On Server there. You can check the aim first with Is Part In View on the view sensor.
When the exact aim gives no option, the part nearest to the view direction inside the cone takes the focus.
Score Option. The highest score wins.The default score prefers a higher Priority, then a nearer target.
| Setting | Default | Effect |
|---|---|---|
| Refresh Interval | 0 s | Seconds between two refreshes while there are targets. 0 refreshes only when the targets change or the input starts. |
| Send Server Requests | true | Send a server option to the server with the built-in RPC. When false, only On Server Request fires. |
| Max Distance Cm | 0 | Most distance from the owner to a target. 0 means no limit. |
| Setting | Default | Effect |
|---|---|---|
| Trace Distance Cm | 300 | Length of the trace and radius of the assist search. |
| Trace Channel | Visibility | Channel of the trace. A part must block it to take the aim. |
| Assist Angle Deg | 0 | Half-angle of the assist cone, up to 45. 0 turns the aim assist off. |
| Assist Stick Deg | 2 | Extra angle that keeps the focused part. |
| Field | Default | Effect |
|---|---|---|
| Target | Set by the component | The actor and the part. |
| Action Id | None | Name of the action that Execute Interaction runs. |
| Tap Action Id | None | Action of a short press on a hold option. None does nothing. |
| Title | Empty | Short name of the target. |
| Prompt | Empty | Text of the action, or the reason that it is not available. |
| Enabled | true | False shows the prompt and runs nothing. |
| Input | Press |
Press or Hold. |
| Hold Seconds | 0.5 | Seconds of a hold. |
| Authority | Local |
Local runs on the machine of the interactor. Server runs on the server. |
| Prompt Location | Zero | World point of the prompt. Zero means the center of the part, or the actor location. |
| Priority | 0 | A higher priority wins over a nearer target. |
On Ns Interactable Actor, the option defaults are Action Id Use, Prompt “Use”, and Authority Server.
The plugin has no console commands, console variables, log category, or debug draw.
To see the state in play, print these values:
Get Targets, Has Option, and Get Option on the Ns Interaction component.Get Focus on the Ns Interaction View Sensor component.| Problem | Cause | Fix |
|---|---|---|
| The view sensor finds nothing. | The owner has no Camera component and no view source is set. | Add a camera, or call Set View Source. |
| The aim passes through a mesh. | The mesh does not block Trace Channel. | Set the collision of the mesh to block the channel. |
| The prompt never shows. | Get Interaction Option returns false, or the target is farther than Max Distance Cm. |
Return true, or raise Max Distance Cm. |
Begin Interact returns false. |
No target gives an option now. | Check the sensor and Get Interaction Option. |
| A server option does nothing on a client. | Send Server Requests is off, or the pawn does not belong to the player controller. | Turn it on, or send the request from your own RPC. |
| The server does not run a request. | The option on the server is disabled, out of reach, or has another Action Id. | Make the server state match the client prompt. |
| The hold stops before the end. | The best target changed during the hold. | Keep the aim on the target, or raise Assist Stick Deg. |
| The focus jumps between two close parts. | Assist Stick Deg is too small. | Raise Assist Stick Deg. |
A client still shows a prompt after Set Interaction Enabled on the server. |
The option of Ns Interactable Actor does not replicate. | Call Set Interaction Enabled on each machine, for example from a replicated variable. |
Set Interaction Enabled changes it only on the machine that calls it.