Skip to main content

Pickup

A class in Root.Township, the global namespace.

An Interactable you can pick up, hold, dock and drop: almost every item in the game. Lives on the item's prefab root; grabs start on the holding client and are synced to the server and others.

Constructors​

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

Fields​

MemberWhat it is
protected GrabPoint bestGrabProtected backing field for BestGrab.
protected Interactor bestGrabInteractorProtected. The hand bestGrab was chosen for.
protected Dictionary<Interactor, GrabPointParameters> interactorToGrabPointProtected. The grab point each holding hand is using.
48 private and internal fields
MemberWhat it is
private static int ActiveTightGripLayerIndexIndex of the "Active Tight Grip" layer. Tight grip colliders move to it briefly while the hand grip is fitted.
private BlockLevel blockLevelBacking field for BlockLevel: how well this blocks in combat. Default cannot block.
private PickupEvent breakEventBacking field for BreakEvent, invoked by Break.
private bool btnInspector button that runs GetInterferees.
private bool bypassMed1hBacking field for BypassMed1h.
private Collider[] childrenCollidersAll child colliders, baked. Copied into Colliders on awake.
private CraftingPart craftingPartBacking field for CraftingPart.
private float distanceThresholdSquaredSquared distance a hand may move from the pickup during locomotion before it is force released.
private PickupDockedEvent dockedEvent behind Docked.
private GrabPointParameters dockedMemoryLeftGrab point the left hand last used when docking, reused on the next grab from the dock. Saved with the pickup.
private GrabPointParameters dockedMemoryRightGrab point the right hand last used when docking. Saved with the pickup.
private PickupDocker dockerHelper that handles docking into and out of docks; Dock comes from it.
private PickupDockingChecker dockingCheckerHelper that finds a dock candidate while the local player holds the pickup.
private bool double1hSurplusPenaltyInspector flag that no code reads.
private DurabilityModule durabilityModuleBacking field for DurabilityModule.
private GrabPoint[] grabPointsBacking field for GrabPoints: where and how hands can hold this.
private float grabPointsScaleScale applied to grab point positions.
private bool hasDistanceThresholdWhether CheckThreshold force releases hands that move too far away.
private static List<Interactor> interactorsToReleaseShared scratch list used by CheckThreshold.
private IInterfereWithDocking[] interfereWithDockingCached cast of interfereWithDockingObjects, behind InterfereWithDocking.
private MonoBehaviour[] interfereWithDockingObjectsChild components that can interfere with docking. Only filled for stackable items by GetInterferees.
private bool isChunkingParentStaticBacking field for IsChunkingParentStatic. When set, grabbing doesn't make the player the chunking parent.
private bool isCumbersomeInspector flag that no code reads.
private bool isEnvironmentalJointBacking field for IsEnvironmental: an environment joint (lever, door) that stays put and doesn't follow the hand's chunk.
private bool isIgnoringMasterTerrainWhether terrain collision is currently off because of the chunk's environment.
private bool isLoggingOwnerChangedWhether ownership changes and sub dock removals by other players are logged.
private bool isNetworkInitializedBacking field for IsNetworkInitialized. False while the docker initializes for networking.
private bool isNextTreatedAsDockedMakes the next grab point score as if docked. For items always spawned from a dock, like pouches.
private bool isStackDestroyingSet by PrepareForStackingDestroy. Stops grabs and the undock on destroy.
private bool isSwingableBacking field for IsSwingable.
private bool isTightGrabBacking field for IsTightGrab: the hand grip is fitted to the tight grip colliders.
private Item itemBacking field for Item.
private PickUpJointType jointTypeBacking field for JointType: how the pickup is joined to the hand. Default velocity joint.
private static Logger loggerNLog logger for this class.
private NetworkRigidbody networkRigidbodyBacking field for NetworkRigidbody.
private PooledObjectDefinition overrideBreakEffectPooled effect spawned on break instead of the global default.
private SoundEffectSet overrideBreakSoundSound played on break instead of the global default.
private PhysicalMaterialPart physicalMaterialCached PhysicalMaterialPart, behind PhysicalMaterial.
private PickupJoints pickupJointsBacking field for JointManager: creates and removes the hand joints.
private PickupInteractionScaler pickupScalerScales the item while held. Only made when the item scales on grab.
private NetworkEntityHandler removeFromPopulationDelegate behind the explicit RemoveFromPopulation event.
private Rigidbody rigidbodyBacking field for Rigidbody. Without one the pickup can't be grabbed.
private const float RotationScorePerDegreeScore added per degree of hand rotation difference when scoring grab points (0.005).
private DockArray subDocksBacking field for SubDocks: docks inside this pickup, like a pouch or bag.
private MethodSync syncBreakNetwork sync for the break message.
private MethodSync syncGrabMemoryNetwork sync that sends the docked grab memory to its last holder when they connect.
private static int TightGripLayerIndexIndex of the "Tight Grip" layer, looked up once in Awake.
private PickupDockedEvent undockedEvent behind Undocked.

Properties​

MemberWhat it is
GrabPoint BestGrab { get; }The grab point chosen by the last score check.
BlockLevel BlockLevel { get; set; }How well the item blocks attacks. Read by impact code when hits land on it.
PickupEvent BreakEvent { get; }Serialized event raised when the item breaks.
bool BypassMed1h { get; }When set, a medium handle held in one hand doesn't lose tool efficiency.
bool CanCraft { get; }False when docked in a dock whose settings don't allow crafting.
HashSet<Collider> Colliders { get; }All colliders on the item and its children.
CraftingPart CraftingPart { get; }The item's CraftingPart, if it can be crafted with.
LootValue CurrentValue { get; set; }The item's loot value, starting from its Item. Crafting raises it to the best part's value.
PickupDock Dock { get; }The dock the item is in, or null.
DurabilityModule DurabilityModule { get; }The item's DurabilityModule, if it wears out.
GrabPoint[] GrabPoints { get; }The item's grab points, set on the prefab.
virtual int InteractorsToRelease { get; }How many hands must remain for letting go to count as a drop. 1 here.
IInterfereWithDocking[] InterfereWithDocking { get; }Child components that can stop the item docking.
bool IsChunkingParentStatic { get; set; }When set, grabbing doesn't make the hand the item's chunking parent.
bool IsCrafted { get; set; }True when the item is part of a crafted object of more than one part.
bool IsCraftedChild { get; set; }True while the item is attached to another part as a crafting child.
bool IsDocked { get; }True while the item is in a dock.
bool IsDockingBlocked { get; set; }When true, letting go doesn't try to dock the item.
bool IsEnvironmental { get; }True for items joined to the world rather than carried. They don't take the hand as chunking parent.
bool IsNetworkInitialized { get; }True once networking is set up for the item's docking.
bool IsPouch { get; }True for the pouch item, which holds others in its sub-docks.
bool IsSwingable { get; }Whether the item counts as a swung weapon.
bool IsTightGrab { get; }When set, the hand closes tightly around the item's colliders.
bool IsTransient { get; set; }Marks the item as temporary (a lit fuse, for example). Most docks refuse transient items.
Item Item { get; set; }The item definition: name, weight, size and docking rules.
PickupJoints JointManager { get; }Handles the joints between the item and the hands holding it.
PickUpJointType JointType { get; }How the item is joined to a hand (velocity joint, empty joint and so on).
float MaximumAngularVelocity { get; private set; }The rigidbody's spin limit when the item spawned, put back by the joints.
NetworkRigidbody NetworkRigidbody { get; }The item's synced rigidbody.
Transform OverrideParent { get; set; }A transform to treat as the item's parent. Set for embedded items and by a bow string.
bool OverridesCenterOfMass { get; protected set; }When true, the hand doesn't adjust the rigidbody's centre of mass while holding it.
PhysicalMaterialPart PhysicalMaterial { get; }The item's material part, which sets its weight multiplier.
float PhysicalWeight { get; }The item's weight times its material's weight multiplier.
float RawWeight { get; }The Item weight, or 0 with no item.
Rigidbody Rigidbody { get; }The item's rigidbody.
Vector3 StoredScaleOffset { get; set; }Position offset when docked, set by crafting to centre crafted items.
float StoreScaleModifier { get; set; }Extra scale when docked, set by crafting so long crafted items fit.
DockArray SubDocks { get; }The docks inside this item, such as a bag's slots.
float TotalWeight { get; }Weight including sub-dock contents and attached crafting parts.
List<Joint> WedgeJoints { get; private set; }Joints holding the item embedded in a surface, such as a stuck arrow.
protected override MultipleNotAllowedAction DefaultMultipleBlockedAction { get; }Replace: a second hand that isn't allowed takes the item from the first.
protected override MultipleInteractionAllowance DefaultMultipleInteractionAllowance { get; }No multiple hands by default.

Events​

MemberWhat it is
event Action<PooledObject> BreakEffectSetupRaised with the pooled break effect after it is spawned, so you can adjust it.
event Action<Interactor, Pickup, PickupDock> DockedRaised when the item goes into a dock.
event PickupDockFilter DockFilterHandlers can set the result to false to stop the item going into a given dock.
event Action<float> OnAffectDurabilityRaised by AffectDurability.
event Pickup.PickupHandler PickupGrabbedRaised after the item is grabbed and joined.
event PickupDockInteractionHandler PreDockedRaised just before the item goes into a dock.
event Action<Interactor, Pickup, PickupDock> UndockedRaised when the item leaves a dock.
event Action WeightChangedRaised when the weight of the item's contents changes.
1 private and internal event
MemberWhat it is
private event NetworkEntityHandler Alta.Populations.IPopulationRemovalMethod.RemoveFromPopulationRaised when the pickup is grabbed or docked, so its population (spawner) stops counting it.

Methods​

MemberWhat it is
void AffectDurability(float affect)Raises OnAffectDurability with the amount, for the durability module to apply.
override bool AssessScore(Interactor interactor, out float score)Scores a hand against the item's grab points (position and angle), or by distance if it has none. Lower is better.
bool AttemptGrabChange(Interactor interactor)Re-picks the best grab point for a hand already holding the item and re-grabs with it.
void Break()Breaks the item: raises BreakEvent, plays the break effect and sound, and on the server destroys it for everyone.
bool CheckDockFilter(Interactor interactor, PickupDock dock)Runs the DockFilter handlers. False if any of them refuses the dock.
override bool CheckInteractAllowedAndReplace(Interactor interactor)The base hand rules, plus the item must have a rigidbody.
void DestroyJoint(Interactor interactor)Removes the joint between the item and a hand and detaches the hand model.
PickupDock.AllowedResult DockInto(Interactor interactor, PickupDock dock, int quantity, bool isInstantMovementForced = false)Docks the item into a dock (a given quantity) and returns whether it was allowed.
void EnsureBestGrabFound(Interactor interactor)Makes sure BestGrab suits this hand, using the remembered grab from the dock if that setting is on.
override void FinishInteraction(Interactor interactor)Lets go: removes the joint, moves the chunking parent, tries to dock, and on clients hands physics back.
bool GetGrabPoint(Interactor interactor, out GrabPointParameters grabPoint)The grab point a hand is using, if it holds the item.
void GetInterferees()Editor button: collects child components that interfere with docking, for stackable items.
Item GetPouchItem()For a pouch, the item type stored in it, or null.
virtual void GrabWith(Interactor interactor, bool isGrabbingFromDock, bool isAddingJoint = true)Moves the item into a hand at the best grab point and joins it. The transform overload just places it.
void GrabWith(Transform interactionPoint)Moves the item into a hand at the best grab point and joins it. The transform overload just places it.
override void Initialize()Sets up docking sync and break messages, and on the server terrain collision handling per chunk.
override void Interact(Interactor interactor)Grabs the item: takes it out of its dock and population, makes the hand its chunking parent and joins it.
override void NetworkStartInteraction(INetworkInteractArgument args, Interactor interactor, Action<Interactable> handleInteractionStart)Starts a grab that came over the network, placing the hand and item where the sender had them.
override void NetworkStopInteraction(InteractArguments args, Interactor interactor, Action<Interactable> handleInteractionEnd)Ends a grab from the network, setting the item's position and velocity from the sender.
override void OnConnected(Player player)Server: sends a joining player the item's dock, and its remembered grab if they held it last.
void OnWeightChanged()Raises WeightChanged.
void PrepareForStackingDestroy()Marks the item as being merged into a stack, so it can't be grabbed or undocked again.
void RecoverGrip(Interactor interactor)Snaps the item back to a hand's grab point.
void ReevaluateTightGrip(Interactor interactor, IEnumerable<Collider> colliders)Client: closes the hand around the item's tight-grip colliders.
override void ReplacedWith(NetworkEntity entity, ReplaceAvoidFlags replaceAvoidFlags)Called when the entity is replaced: hands move to the new entity's pickup unless told not to.
void ReplaceWith(Pickup pickup)Moves every hand on this item to another pickup, or to what a Spawner last spawned.
override void ReplaceWith(Spawner spawner)Moves every hand on this item to another pickup, or to what a Spawner last spawned.
void SetupGrabPoint(Interactor interactor, GrabPoint grabPoint)Sets the grab point and hand to use for the next grab.
bool TestGrabPoints(Transform interactionPoint, HandIndex handIndex, out float score)Scores every free grab point against a hand position and rotation, and picks the best.
void TreatNextPickupAsIfDocked()Makes the next grab point check score as if the item were docked.
void Undock(Interactor interactor, bool isScalingBack, int quantity)Takes the item, or a quantity of a stack, out of its dock.
void UpdateRigidbody()Re-fetches the rigidbody component.
protected virtual void AddSecondaryCollision()Adds a secondary collision check to the item when the local player grabs it with one hand.
protected virtual void Awake()Builds the joint, docking and scaling helpers, collects colliders and hooks sub-dock weight changes.
protected virtual void CleanDestroy()Clears the docking check and undocks the item from its dock when it goes away.
protected virtual void CreateJoint(Interactor interactor)Joins the item to a hand using its joint type.
protected virtual void OnDisable()Stops the grab and let-go sounds.
protected virtual void OnDrawGizmosSelected()Editor: draws the grab points.
protected virtual void OnEnable()Starts the grab and let-go sounds (not on a headless server).
protected override void OnLastInteractorPlayerChanged()Forgets the remembered grab points when a different player handles the item.
protected void UpdateGrabPoint(GrabPointParameters grabPointParameters, Interactor interactor)Sets BestGrab from saved grab point parameters for a hand.
23 private and internal methods
MemberWhat it is
private void CheckThreshold(PlayerController player, Vector3 oldPosition, Vector3 newPosition, LocomotionFunction function)Handler for the holder's PositionAboutToChange: force releases hands that end up further than the distance threshold from the pickup.
private void EnteredChunk(Chunk chunk)Server: when the pickup enters a location chunk whose environment disables terrain collision, turns off collision with the master terrain.
private int GetQuantity()Count for event logs: 1 for a plain pickup, or the total stored in its sub docks.
private void IgnoreTerrain(bool isIgnoringMasterTerrain)Turns collision between every pickup collider and the master terrain collider off or on.
private void InteractionEndedSound(Interactable interactable, Interactor interactor)Client: plays the let go sound (or the item's override) at the hand when released.
private void InteractionStartedSound(Interactable interactable, Interactor interactor)Client: plays the grab sound (or the item's override) at the hand when grabbed.
private void LeftChunk(Chunk chunk)Server: turns master terrain collision back on when leaving a no terrain collision chunk for one that isn't.
private void OnDestroy()Calls CleanDestroy unless the game is quitting, reloading or the entity is already being destroyed.
private void OnDocked(Interactor interactor, Pickup pickup, PickupDock dock)Handler for the docker's docked event: logs it, removes the pickup from its population, raises Docked and raises the sync priority.
private void OnDrawGizmos()Draws the interaction scaler's gizmos in the editor.
private void OnPreDocked(Interactor interactor, Pickup pickup, PickupDock dock)Forwards the docker's pre docked event to PreDocked.
private void OnUndocked(Interactor interactor, Pickup pickup, PickupDock dock)Handler for the docker's undocked event: logs it, raises Undocked and clears the docked sync priority.
private void IBuildRendererPostBake.PostBake()Build bake step: strips null entries from childrenColliders.
private void ProcessGrabbedEvent(Interactor interactor)Server (or local test): broadcasts a PlayerGrabbedPrefabEvent on the township event bus when a player grabs this.
private void SaveGrabForInteractor(Interactor interactor)Server: stores the grab point that hand used as the left or right docked grab memory.
private void SceneDestroy(NetworkEntity entity, bool isUnload)Handler for the entity's DestroyedByScene event; calls CleanDestroy.
private void SerializeGrabMemory(Stream stream, ref GrabPointParameters memory)Reads or writes one hand's grab memory, with a flag for whether it is set.
private bool ShouldTeleportToHand(Interactor interactor)True when the pickup is far enough from the hand (past the global minimum) to be moved there on grab. Never for empty joints.
private void SyncBreak(IPlayer player, Stream stream)Remote clients: runs Break when the server says the pickup broke.
private void SyncGrabMemory(IPlayer player, Stream stream)Client: receives the left and right docked grab memory from the server; the server rejects it as unauthorized.
private void TeleportToHand(Interactor interactor)Moves the pickup to the hand's interaction point.
private bool TryDock(Interactor interactor)On release, docks into the best dock candidate. True if it was already docked or got docked.
private void UndockLog(Interactor interactor, Pickup pickup, PickupDock dock)When owner logging is on, logs when another player takes something out of this pickup's sub docks.

Used in​

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

CraftingMeltingAllowedModifier.pickupMaps, ForgedModel<TB, TA>.pickup, RecyclerOutputSlot.NewSource, Smelter.CheckSmelt, Smelter.MouldAdded, Smelter.MouldRemoved, BuilderDock.BlockFilter, RecipePlacer.AddDefinition, RecipePlacer.ClearDefinition, RecipePlacer.PageFilter, TimberBlock.spawnedPickups, TimberBlock.UpdatePickupCollision, DockedDissolver.DissolveItem, CharacterCollisionController.DelaySetColliders, DockStore.CanAdd, DockStore.Peek, DockStore.Search, DockStore.TryPeek, DockStore.TryPop, DockStore.TryPush, Hand.AverageCenterOfMass, HandStore.CanAdd, HandStore.Peek, HandStore.Search, HandStore.TryPeek, HandStore.TryPop, HandStore.TryPush, IInventoryStore<T>.CanAdd, IInventoryStore<T>.Peek, IInventoryStore<T>.Search, IInventoryStore<T>.TryPeek, IInventoryStore<T>.TryPop, IInventoryStore<T>.TryPush, Cookable.pickup, Cookable.Pickup, CookingGarnishComponent.pickup, AdditionalOwnedDock.basePickup, AdditionalOwnedDock.CheckDockFilter, AdditionalOwnedDock.DeregisterDock, AdditionalOwnedDock.RegisterDock, CraftingPart.Break, CraftingPart.pickup, CraftingPart.Pickup, DecraftingComponent.AddPickup, DecraftingDeck.PickupFilter, DisableLightOnDock.CheckEnabledEnable, DisableLightOnDock.ForceEnable, DisableLightOnDock.pickup, GenericAssemblyStation.DockFilter, GenericAssemblyStation.GetAdditionalChiselables, GenericAssemblyStation.InsertPiece, GenericAssemblyStation.RemovePiece, GenericCraftingComponent.pickup, GenericCraftingComponent.Pickup, GenericCraftingStation.AddItemOnReleaseCoroutine, GenericCraftingStation.CheckPageForRecipe, GenericCraftingStation.IsPickupValidToAdd, GenericCraftingStation.OnPageDocked, GenericCraftingStation.OnPageUndocked, GenericCraftingStation.PageFilter and 413 more.