Skip to main content

Interactor

A class in Root.Township, the global namespace.

The grabbing part of a hand. It finds Interactables in its trigger, picks the best one, starts and stops interactions and syncs them. A ControllerExtension on each hand of a player body; the owning client drives it and the server checks and relays.

Constructors​

MemberWhat it is
Interactor()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
const float MaximumScorefloat.MaxValue. A score at this value means the interactable can't be picked.
31 private and internal fields
MemberWhat it is
private Vector3 basePositionDeclared but never used.
private Quaternion baseRotationDeclared but never used.
private InteractionChannel channelsThe interaction channels this interactor works on, unless overridden.
private int collisionLayerLayer of the trigger object. Used to build collisionMask.
private int collisionMaskLayers the overlap check hits. Baked from collisionLayer.
private GrabAssistController grabAssistControllerThe grab assist helper, present only for the local player when grab assist is on.
private AnimationCurve hapticHaptic curve played on a successful grab and on the holder's hand when someone asks to take the item.
private Interactable interactingWithBacking field for InteractingWith.
private float interactTimeoutSeconds an interaction attempt stays valid when timeouts are on. Default 2.
private bool isControllerBasedWhether the trigger lives on a separate child object (hands) rather than a rigidbody on this object.
private bool isDuringInteractionStartedSet while StartInteract runs, so a release during start can cancel it.
private bool isNetworkedWhether starts and ends are sent over the network and received ones applied. Default true.
private bool isTimingOutInteractionAttemptWhether interaction attempts expire after interactTimeout.
private JointBreakDetector jointBreakDetectorDetector whose joint break event ends the interaction.
private Vector3 lastPhysicsTriggerPositionTrigger position from the last physics step, the start of the overlap capsule.
private float lengthTrigger capsule length. Zero or less means a sphere.
private Vector3 localEulerLocal rotation of the trigger object.
private Vector3 localOffsetLocal position of the trigger object. Mirrored for the right hand.
private static readonly Logger loggerNLog logger for this class.
private readonly Collider[] overlapReused buffer of up to 10 colliders for the overlap check.
private InteractionChannel? overrideChannelsChannels set by SetOverrideInteractionChannels; null uses channels.
private float radiusTrigger radius, scaled by the object's scale.
private AnimationCurve requesteeHapticHaptic curve played on the requesting hand while waiting for another player to let go.
private float startOfInteractAttemptTime the current interaction attempt began, for the timeout.
private MethodSync syncConfirmationRequestNetwork sync for the confirmation request message.
private MethodSyncStruct<InteractArguments> syncEndNetwork sync for the interaction end message.
private MethodSyncStruct<InteractArguments> syncStartNetwork sync for the interaction start message.
private MethodSyncStruct<GrabPointArguments> syncStartGrabPointNetwork sync for the pickup grab point start message.
private bool toggleHoldDelayBlocks toggle hold for a moment after it was released.
private TriggerShape triggerThe sphere or capsule trigger whose Entered event feeds AddOverlap.
private Transform triggerObjectTransformBacking field for TriggerObjectTransform.

Properties​

MemberWhat it is
InteractionChannel Channels { get; }The interaction channels this hand can use. An override, if set, replaces the prefab's channels.
Transform Folder { get; }The body's transform, or the interactor's own without a controller.
Interactable ForwardSource { get; private set; }The interactable the last StartInteract was called on, before forwarding picked the real target.
HandGrip GripAnimator { get; }The hand's grip animator, if it has one.
bool HasGripAnimator { get; private set; }Whether the hand had a grip animator at setup.
Interactable InteractingWith { get; }What this hand is holding or using now, or null.
Transform InteractionPoint { get; }The point used for distance scoring: the hand's grip point.
static int IsDuringPhysicsOverlap { get; set; }Static counter, above zero while an interaction is starting from a trigger overlap or being stopped.
bool IsInteracting { get; }True while InteractingWith is set.
bool IsToggleHolding { get; private set; }True while the hand holds something with toggle grab, so letting go of the button doesn't drop it.
List<Interactable> OverlapInteractables { get; }The interactables found in the last overlap check.
Transform TriggerObjectTransform { get; }The transform of the hand's trigger sphere or capsule.
1 private and internal property
MemberWhat it is
private bool HasTimedOut { get; }True when isTimingOutInteractionAttempt is set and more than interactTimeout seconds have passed since the attempt began.

Events​

MemberWhat it is
event GeneralDelegates.BoolUpdater GetGrabAssistBlockHandlers can set the value to true to turn off grab assist for this hand.
event InteractionHandler InteractionEndedRaised after an interaction stops.
event InteractionHandler InteractionStartedRaised after an interaction has started and been sent.
event InteractionHandler PreInteractionStartedRaised just before the interactable's Interact runs.

Methods​

MemberWhat it is
void CheckHold(PlayerInput controller)Run when the grab button is pressed: tries grab assist, or picks the best overlapping interactable and starts on it.
void CheckRelease(PlayerInput controller, bool isDisabling)Run when the grab button is let go: stops the interaction unless toggle-holding (or the hand is being disabled).
int GetColliderOverlap(out Collider[] colliders)Sweeps the hand's trigger since the last physics step and returns how many colliders it hit, with the shared buffer.
void GetConfirmationOnInteractable(Interactable targetInteractable)Starts on the interactable, or if another player holds it, buzzes both and waits for them to let go while you keep holding.
override void InitializeControllerExtension()Sets up the interact sync messages, the trigger offset (mirrored for the right hand) and grab assist on the local player.
bool IsGrabAssistBlocked()Whether any GetGrabAssistBlock handler is blocking grab assist.
override void OnConnectedToPlayer(Player player)Server: tells a newly arrived player what this hand is holding, as a forced hold.
void ResetOverrideInteractionChannels()Clears a channel override so Channels goes back to the prefab's.
void ResetTimeout()Restarts the interact attempt timer, so a timed-out hand can grab again.
bool SelectBestFromCurrent(out Interactable bestInteractable)Overlaps the trigger now and returns the lowest-scoring interactable that accepts this hand.
void SetOverrideInteractionChannels(InteractionChannel newChannels)Replaces this hand's interaction channels until reset.
Interactable StartInteract(Interactable interactable, bool isFromNetwork = false, bool isForced = false, bool isForcingHold = false)Starts interacting after following forwards and checking the target allows it. Sends the grab and keeps a held item out of chunk saves.
void StopInteract(bool isFromServer = false, bool isForced = false)Ends the current interaction, sends it unless it came from the server, and restores the item's save mode.
Interactable SwapInteract(Interactable interactable, bool isForced = false)Stops the current interaction and starts on another interactable.
28 private and internal methods
MemberWhat it is
private void AddOverlap(Collider collider)Handler for the trigger's Entered event: while the local player holds Interact, assesses the new interactable and grabs it if it scores.
private bool CheckGrabAssist()Runs the grab assist check when grab assist is on and not blocked; true if it handled the grab.
private void ClearAssist()Disables and drops the GrabAssistController. Called when the grab assist setting is turned off and on destroy.
private void FixedUpdate()Records the trigger object's position each physics step, so the overlap capsule spans last step to now.
private int GetColliderOverlap()Sweeps the hand's trigger since the last physics step and returns how many colliders it hit, with the shared buffer.
private bool IsGrabAssistEnabledAndNotBlocked()True when a grab assist controller exists and no GetGrabAssistBlock listener blocks it.
private void JointBroken(JointBreakDetector detector, float force)Handler for the joint break detector: stops the current interaction when the hand joint breaks.
private void NetworkStartInteraction(Interactable interactable)Callback for a networked start: stops any current interaction and starts the new one as coming from the network.
private void NetworkStopInteraction(Interactable interactable)Callback for a networked end: stops the interaction if it is still with that interactable.
private void OnDestroy()Clears toggle hold, stops interacting, removes grab assist and unhooks the settings listener.
private void OnDisable()Unhooks the joint break, trigger and controller action handlers and disables grab assist.
private void OnDrawGizmosSelected()Editor gizmo: the trigger sphere or capsule, or in play mode the grab assist capsule.
private void OnEnable()Hooks the joint break detector, the trigger's Entered event and the Interact, HardInteract, ToggleGrab and ReleaseToggleGrab actions.
private void OnStartInteractionAttempt()Marks the start time of an interaction attempt, used by the timeout. Also passed to grab assist.
private void ReadStartArguments(INetworkInteractArgument args)Applies a received start message: waits for the target entity to spawn, then starts the interaction, or sends an end at once if the local hand already let go.
private void ReleaseToggleHold(PlayerInput playerInput)Handler for ReleaseToggleGrab: ends toggle hold and stops interacting if Interact isn't held. Briefly blocks a new toggle hold.
private bool SelectBest(int overlapCount, out Interactable best)Collects the interactables in the overlap buffer that match the channels and picks the one with the lowest AssessInteraction score.
private void SendNetworkInteract(Interactable interactable, bool isForced, bool isForcingHold)Sends the interaction start to the chunk, as a grab point message for pickups with a best grab, otherwise an interact message.
private void SendNetworkInteractEnd(Interactable interactable, bool isForced)Sends the interaction end message to the chunk. Only the local owner, or the server when forced, sends it.
private bool SetupCollisionMask()Editor bake step: builds collisionMask from the layers that collide with collisionLayer.
private bool SetupTriggerObject()Editor bake step: for controller based interactors, creates the child trigger object with a sphere or capsule and kinematic rigidbody.
private void SyncConfirmationRequest(IPlayer player, Stream stream)Receives a confirmation request: buzzes the local holder's hand, or forwards the request on (server to the player, client to the chunk).
private void SyncEnd(IPlayer player, Stream stream, InteractArguments args)Receives an interaction end. The server checks the sender owns this interactor and relays it, then the interaction is stopped.
private void SyncStart(IPlayer player, Stream stream, InteractArguments args)Receives an interaction start. The server ignores dead players, checks the sender owns this interactor and relays it to the chunk.
private void SyncStartGrabPoint(IPlayer player, Stream stream, GrabPointArguments args)Same as SyncStart but for pickup grabs that carry the grab point.
private void ToggleHold(PlayerInput controller)Handler for ToggleGrab: turns on toggle hold while interacting, so letting go of Interact doesn't drop.
private void UpdateGrabAssist(Settings obj)Creates or clears the grab assist controller to match the game's grab assist setting.
private IEnumerator WaitForConfirmation(Interactable targetInteractable, Interactable forwardInteractable) (iterator)Coroutine used when grabbing something another player holds: buzzes both hands, then grabs once they let go, unless the hand moves away or Interact is released.

Used in​

Members of other types that take, return or hold a Interactor:

ActionOrb.HandleGrabbed, ActionOrb.StartMovingBack, Smelter.CheckSmelt, Smelter.MouldAdded, Smelter.MouldRemoved, BuilderDock.BlockFilter, ChiselingTool.StartCheckHaptic, ChiselingTool.StopCheckHaptic, ChiselingTool.TriggerHaptic, RecipePlacer.AddDefinition, RecipePlacer.ClearDefinition, RecipePlacer.PageFilter, TimberBlockSpawner.IsNewPlayer, TimberBlockSpawner.SnapPoint, TimberBlockSpawner.StartCheckingPosition, CaveTeleporter.HandFilter, DockedDissolver.DissolveItem, CharacterCollisionController.collidersMap, CharacterCollisionController.DelaySetColliders, CharacterCollisionController.DisableColliders, CharacterCollisionController.disabledCache, CharacterCollisionController.EnableColliders, CharacterCollisionController.enablingCoroutines, CharacterCollisionController.SetColliders, Hand.Detach, Hand.Interactor, Hand.MoveCenterOfMassToGripPoint, Hand.ResetCenterOfMass, HandStore.Source, InteractionCollisionController.InteractionEnded, InteractionCollisionController.InteractionStarted, InteractionCollisionController.interactor, Inventory.LeftHand, Inventory.RightHand, AdditionalOwnedDock.CheckDockFilter, AdditionalOwnedDock.CheckInteractionFilter, AdditionalOwnedDock.DeregisterDock, AdditionalOwnedDock.RegisterDock, ConfirmationCraftingPart.InteractionPopout, CraftingOptions.AttemptCraft, CraftingOptions.Cancel, CraftingOptions.RequestCraft, CraftingPart.CheckPossibleConnections, DisableLightOnDock.CheckEnabledEnable, DisableLightOnDock.ForceEnable, GenericAssemblyStation.CalculateDockPosition, GenericAssemblyStation.DockFilter, GenericAssemblyStation.InsertPiece, GenericAssemblyStation.RemovePiece, GenericCraftingPiece.FilterPop, GenericCraftingPiece.Grab, GenericCraftingPiece.SpawnRefuseForInteractor, GenericCraftingStation.ComponentReleased, GenericCraftingStation.DockingFilter, GenericCraftingStation.GrabResult, GenericCraftingStation.GrabResultFilter, GenericCraftingStation.OnPageDocked, GenericCraftingStation.OnPageUndocked, GenericCraftingStation.PageFilter, CosmeticPresetTrophy.DisableGhostHands and 599 more.