⚡Interactor
Last updated AC v1.5.3
Overview
This component stores the Index and GameObject of an Interactable and invokes events that can be used to create Reactions according to each Interactable value. It also executes the Interaction logic on the Interactable.

The inspector is split into three tabs: General, Events and Reactions.
How to use it
Place the Interactor on your character and add an Interaction Area (Collider). This will allow it to detect Interactables in the scene. When an Interactable is inside the Collider, the Interaction logic can be activated.

To activate the interaction you can add an Input to your Malbers Input Component and connect it directly to the Interactor's Interact() method.

If the Interactable is set to be Automatic then the interaction will not need manual activation: it fires the moment the Interactable is focused.
Use the Reactions lists to have different reactions for different Interactable IDs.
How it Works
The Interactor does not listen to OnTriggerEnter itself. On enable it attaches a Trigger Proxy to the Interaction Area collider and subscribes to it, passing down its own Layer, Trigger Interaction and Tags.
It keeps two sets at runtime:
Inside — every Interactable currently inside the Interaction Area, focused or not.
Focused — the Interactables the Interactor is currently focusing. With Single Focus on, this is at most one.
Single Focus
Single Focus is on by default and changes how focus is handed around:
The newest Interactable to enter the area takes the focus. The previous one receives On Unfocused but stays inside as a candidate.
When the focused Interactable leaves, is picked up, or is disabled, the closest Interactable still inside the area is focused automatically.
With Single Focus off, every Interactable inside the area stays focused at the same time, and Interact() fires on all of them.
Parameters
General
Layer
What layer will be checked on the Interactables.
Trigger Interaction
Does the Interactor interact with triggers or just colliders?
Tags
Malbers Tags to check on the Interactables. Leave it empty to allow everything. These Tags are merged into the Trigger Proxy created on the Interaction Area.
ID
Index of the Interactor. This parameter is received by the Interactable when Interact() is called, so the Interactable can check who activated its logic.
Interaction Area
Reference for the Collider used to find Interactables [On Trigger Enter]. It is forced to Is Trigger automatically.
Single Focus
Focus only one Interactable at a time. On by default. See Single Focus above.
Debug
The bug icon next to the tabs. Logs every focus and interaction. In Play Mode the inspector also lists the Focused Item and everything Inside the area, with their IDs.
Events
On the Events tab.

On Interact with (GameObject)
Invoked when the Interact() method succeeds. Sends the Interactable GameObject as parameter.
On Interact with (Int)
Invoked when the Interact() method succeeds. Sends the Interactable Index as parameter.
On Focused (GameObject)
Invoked when an Interactable takes the focus. Sends the Interactable GameObject.
On Unfocused (GameObject)
Invoked when an Interactable loses the focus: it left the area, it was picked up, or another Interactable took the focus from it. Sends the Interactable GameObject.
Reactions
On the Reactions tab there are now two lists.
[Insert Image - The Reactions tab with the Reactions and Focus Reactions lists]
Reactions
Fired when the Interactor interacts with an Interactable.
Description
Free text label for the row.
Is
How the Index is compared: Equal, Not Equal, Greater, Less, Greater Equal, Less Equal.
Index
Interactable Index to compare against. Set it to 0 or a negative value to run this reaction for all Interactables.
Reaction
Reaction applied on the Interactable GameObject when the Index matches.
Focus Reactions
Same shape, but fired on focus instead of interaction. Each row has two Reaction slots:
On Focused — applied on the Interactable when it takes the focus.
On UnFocused — applied on the Interactable when it loses the focus.
Use this pair to highlight an Interactable, show a key prompt, or outline a mesh while the character is looking at it.
Public Methods
Callable from UnityEvents or code:
Interact()— interact with everything currently focused, in reverse order.Interact(GameObject)/Interact(Component)/Interact(IInteractable)— interact with one specific Interactable.Focus(IInteractable)/UnFocus(IInteractable)— focus or release one Interactable by hand.FocusNext()— Single Focus only. When nothing is focused, focuses the closest active Interactable still inside the area.RemoveFocusedItem(IInteractable)— drop an Interactable from both the focus and the candidates, e.g. because it was just picked up, then hand the focus to the next one inside.Restart()— clear the focus and the candidates and invoke the focus events with null.
Properties:
ID— the Interactor Index.Active— enable/disable the Interactor.ItemInFocus— true while at least one Interactable is focused.FocusedInteractables— the focused set.Inside— every Interactable currently inside the area.Proxy— the Trigger Proxy created on the Interaction Area.
Code-level hooks (System.Action<IInteractable>): OnFocusing, OnUnFocusing, OnInteract.
Last updated