codeAPI Reference
s&box BasePickup: Trigger and collision-based pickup system
BasePickup API Reference
BasePickup is an abstract Component for creating trigger or collision-based pickups (weapons, ammo, items).
Type Signature
CSHARP
public abstract class BasePickup : Component, Component.ITriggerListener, Component.ICollisionListenerRequired Component
CSHARP
[RequireComponent] public Collider Collider { get; set; }Properties
- SoundEvent PickupSound - Sound to play when picking up this item.
Virtual Methods
- bool CanPickup(Player player, PlayerInventory inventory) - Check if the player can pick up this object. Override for custom logic (e.g., inventory full, class restrictions). Returns true by default.
- bool OnPickup(Player player, PlayerInventory inventory) - Give the player the effect of this pickup. Override to implement custom pickup logic (e.g., add ammo, give weapon). Returns true to consume the pickup (destroy it), false to keep it.
Interface Implementations
ITriggerListener.OnTriggerEnter
Called when a GameObject enters the trigger collider. Checks for Player component and calls CanPickup/OnPickup.ICollisionListener.OnCollisionStart
Called when a collision occurs. Similar to trigger but uses collision detection. Useful for pickups that should physically collide.RPC Method
CSHARP
[Rpc.Broadcast]
protected void PlayPickupEffects(Player player)Notes
- Both trigger and collision listeners are implemented - use whichever fits your pickup type.
- Host-only logic (Networking.IsHost check) ensures pickups only process on the server.
- DestroyGameObject() is called after successful pickup by default (return true from OnPickup).
Was this helpful?