Skip to main content

Interactable

A class in Root.Township, the global namespace.

Anything a hand can grab or use: the base class for Pickup, levers, buttons, containers and more. A NetworkEntityBehaviour on the item; interactions start on the client and are synced through the Interactor.

Constructors​

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

Fields​

MemberWhat it is
protected bool isDuringInteractTrue while CheckInteractAllowedAndReplace is making other hands let go.
7 private and internal fields
MemberWhat it is
private InteractionChannel channelsBacking field for Channels. Only interactors sharing a channel can use this.
private bool isNetworkedBacking field for IsNetworked. When false, networked start and stop messages are ignored.
private PlayerController lastPlayerInteractorBacking field for LastPlayerInteractor.
private static readonly Logger loggerNLog logger for this class.
private MultipleInteractionAllowance multipleAllowanceBacking field for MultipleAllowance: whether more than one hand, or more than one player, may hold this at once.
private MultipleNotAllowedAction multipleNotAllowedActionWhat happens when a disallowed extra interactor tries: block the new one, or make the old one let go.
private float overrideInteractionPriorityModifierMultiplies the distance score when picking what a hand grabs; lower wins. Zero means use the defaults (containers count double).

Properties​

MemberWhat it is
SaveMode BaseSaveMode { get; set; }The save mode to go back to after being held. Child for embedded parts.
InteractionChannel Channels { get; set; }Which interaction channels this listens on. A hand only sees it if their channels overlap.
List<Interactable> ForwardTo { get; }Interactables to pass interactions on to. The last one added wins.
List<Interactor> Interactors { get; }The hands interacting with this now.
bool IsInteractable { get; set; }Whether hands can find this. Same as the component being enabled.
bool IsInteractedWith { get; protected set; }True while at least one hand is on it.
bool IsNetworked { get; set; }When false, interactions on this are not started or stopped from network messages.
int LastInteractorPlayerId { get; protected set; }User id of the last player who interacted with this. 0 if none.
NetworkEntity LastInteractorRoot { get; private set; }The body entity of the last player who interacted with this.
PlayerController LastPlayerInteractor { get; set; }The body of the last player who interacted with this. Setting it updates the id and root.
MultipleInteractionAllowance MultipleAllowance { get; }Flags for whether two hands of one player, or several players, can hold this at once.
protected virtual MultipleNotAllowedAction DefaultMultipleBlockedAction { get; }What a subclass does by default when a second hand isn't allowed. Block here.
protected virtual MultipleInteractionAllowance DefaultMultipleInteractionAllowance { get; }Which multiple interactions a subclass allows by default. None here.

Events​

MemberWhat it is
event Action<Interactable, Interactor> InteractionEndedRaised when a hand stops interacting with this.
event InteractionFilter InteractionFilterHandlers can set the result to false to stop a hand picking this.
event Action<Interactable, Interactor> InteractionStartedRaised when a hand starts interacting with this.

Methods​

MemberWhat it is
virtual bool AssessInteraction(Interactor interactor, out float score)Runs the InteractionFilter handlers, then AssessScore. Returns false if a filter blocked it.
virtual bool AssessScore(Interactor interactor, out float score)Scores this for a hand: squared distance from the grip point, times a per-prefab modifier. Lower wins; containers count double.
virtual Interactable CheckForward(Interactor interactor, out bool isForced)Returns the interactable an interaction should really go to: the last entry in ForwardTo, or itself.
virtual bool CheckInteractAllowedAndReplace(Interactor interactor)Checks multiple-hand and multiple-player rules. Depending on settings, either blocks the new hand or makes the old ones let go.
virtual void FinishInteraction(Interactor interactor)Removes the hand, clears IsInteractedWith when none are left and raises InteractionEnded.
void ForceDrop(bool isForcingClient = false)Makes every hand on this let go.
void ForceLastInteractedPlayerID(int id, PlayerController lastPayerInteractor)Sets the last interacting player id and body directly.
override void Initialize()Hooks the prefab's destroy so every hand lets go when it is destroyed. Embedded parts get Child save mode.
virtual void Interact(Interactor interactor)Adds the hand, sets IsInteractedWith, records the player and raises InteractionStarted.
virtual void NetworkStartInteraction(INetworkInteractArgument message, Interactor interactor, Action<Interactable> handleInteractionStart)Starts an interaction that came over the network, logging if the hand wouldn't normally be allowed.
virtual void NetworkStopInteraction(InteractArguments message, Interactor interactor, Action<Interactable> handleInteractionEnd)Ends an interaction that came over the network.
virtual void ReplacedWith(NetworkEntity entity, ReplaceAvoidFlags replaceAvoidFlags)Called when the entity is replaced: hands move to the new entity's interactable unless told not to.
void ReplaceWith(Interactable interactable)Moves every hand on this to another interactable, or to what a Spawner last spawned. Used when an item turns into another.
virtual void ReplaceWith(Spawner spawner)Moves every hand on this to another interactable, or to what a Spawner last spawned. Used when an item turns into another.
protected virtual void OnLastInteractorPlayerChanged()Override hook, called when a different player interacts with this.
protected virtual void OnValidate()Editor: fills in the multiple-interaction defaults if they were never set.
protected virtual void Start()Empty override hook.
5 private and internal methods
MemberWhat it is
private void NetworkDestroyed(NetworkPrefab prefab)Handler for the prefab's (or parent prefab's) PreDestroyed event: force stops every interactor holding this.
private void TestLeftHand()Editor context menu: makes the local player's left hand start interacting with this.
private void TestLeftHandEnd()Editor context menu: makes the local player's left hand stop interacting.
private void TestRightHand()Editor context menu: makes the local player's right hand start interacting with this.
private void TestRightHandEnd()Editor context menu: makes the local player's right hand stop interacting.

Used in​

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

ActionOrb.HandleGrabbed, ActionOrb.StartMovingBack, ChiselingTool.StartCheckHaptic, ChiselingTool.StopCheckHaptic, TimberBlockSpawner.handles, TimberBlockSpawner.SnapPoint, TimberBlockSpawner.StartCheckingPosition, CaveTeleporter.HandFilter, CaveTeleporter.handTrigger, CharacterCollisionController.DisableColliders, CharacterCollisionController.EnableColliders, Hand.Detach, Hand.MoveCenterOfMassToGripPoint, Hand.ResetCenterOfMass, InteractionCollisionController.InteractionEnded, InteractionCollisionController.InteractionStarted, AdditionalOwnedDock.CheckInteractionFilter, ConfirmationCraftingPart.InteractionPopout, CraftingOptions.AttemptCraft, CraftingOptions.Cancel, CraftingOptions.RequestCraft, CraftingPart.CheckPossibleConnections, GenericCraftingPiece.FilterPop, GenericCraftingPiece.Grab, GenericCraftingPiece.popInteractable, GenericCraftingStation.ComponentReleased, GenericCraftingStation.fakeInteractable, GenericCraftingStation.GrabResult, GenericCraftingStation.GrabResultFilter, CosmeticPresetTrophy.DisableGhostHands, CosmeticPresetTrophy.EnableGhostHands, CosmeticPresetTrophyTrigger.TrophyGrabbed, CosmeticPresetTrophyTrigger.TrophyReleased, CosmeticScrollElement.FilterInteractionAfterRelease, CustomizationPickup.DestroyOnInteractEnd, EditableSlot.AttemptPlace, EditableSlot.Filter, EditableSlot.InteractedWith, EditableSlot.remover, MainMenuShopInterface.throttleInteractable, ImpactTool.Grabbed, ImpactTool.Released, PickupBreakOnImpact.DisableBreak, ActiveEat.Cancel, ITarget.Interactable, PickupAgent.InteractionChanged, Schmeechee.Dropped, Schmeechee.PickedUp, Target.interactable, Target.Interactable, Chest.HandleInteracted, CommunalStorage.FilterInteraction, KeyItem.DeRegisterIK, KeyItem.RegisterIK, Lock.RecentGrab, PickupDock.CheckForward, PlayerDocks.Filter, StabilizeJointContainer.StartHandlingToPositionChanges, StabilizeJointContainer.StopHandlingToPositionChanges, StabilizePickupJoint.StartHandlingToPositionChanges and 308 more.