Slots / Locking Slots

What are locked slots?

Locking a slot temporary renders it unusable, preventing the player from adding and removing items to and from it. Meaning if an item is already in the slot, you can't remove it or replace it. If the slot is locked and empty you can't add anything to it until it is unlocked.

An example use case of locked slots is our Crafting Workstations. When crafting is in progress all tool slots on a workstation are locked. This prevents the player from swapping tools out with others mid-craft in an attempt to try and game the crafting system into giving better results. Forcing the player to commit to a particular tool before they start crafting encourages them to prepare correctly.

How to Lock & Unlock a Slot

Get a reference to the AC_Inventory_Storage component for the slot. On it, call lockSlot and provide the SlotID through the input pin on the node. Unlocking a slot works the same way, you would just call unlockSlot instead.

Locked Slot Persistence

It is important to note that the state of locked slots does not persist between restarts. As in if you lock a slot and restart the game, the slot will not be locked when you get back. Locked slots only live in the current session.

To make it persist you will need to either track the lockedSlots array in the AC_Inventory_Storage save game (make sure to update both the save and load functions), or build your logic to reinitialize the lock on the next play.

The workstation is designed to continue crafting on a restart, and whenever crafting starts it locks the tool slots.

Lock & Unlock related functions

You will find the following lock and unlock related functions on the AC_Inventory_Storage component holding the slot:

lockSlot to lock a slot using the slot ID.
unlockSlot to unlock a slot using the slot ID.
getLockedSlots returns an array of all slot IDs that are currently locked.
isSlotLocked? returns true or false if the provided slot ID is locked.
areAllSlotsLocked? input an array of slot IDs and it will return true if all of the slots in the array are locked.

Event Dispatchers

For single player games you can bind into either event to get notified when any slot is locked or unlocked. For multiplayer games bind into the one that corresponds with where you need the data.

onLockSlotsChange called (on the server) when any slot is locked or unlocked.
onLockSlotsChangeUI called (on the client) when any slot is locked or unlocked.