Auto-Use Items
Last updated
Last updated
Auto-use items, such as potions or the loudspeaker, are those that don't need to be selected/equipped to use. Just press their button/shortcut and their effects are activated.
The flow for making an auto-use item is very similar to other gadgets, except for the following steps:
In its Use Item Details
in its PDA's Custom Item Details
, set AutoUse
to true.
In its Item Executor, instead of listening to the initialize, use Event Auto Use
to define your "on use" behavior.
If you want your item to work without having an ability, e.g. you just want to trigger an emote or modify some local state, you can do this. You won't need to provide an ability asset. However, you will need to manually inform the system when you're finished performing your action (normally we use the ability's activation to trigger the action being "completed"). This can be done with the Mark Local Item Executed
event.
Typically for auto-use items that have abilities, you don't need to mark them as executed. Once the ability triggers, the item is considered finished. To trigger the ability, use TriggerAutoUseAbility
NOTE: Don't use ExecuteAbility
directly, since TriggerAutoUseAbility
also handles if the ability fails to execute (if the ability fails, we still need to mark the use-item as done). If we don't handle this, failing to run the ability could result in the item never getting cleaned up, and so blocking using other items.
You can also configure ability items to require manual teardown instead of immediately tearing down the auto use item when the ability activates. Consider e.g. potions, where we'd want the visuals to remain present for the whole drink animation, rather than disappearing when the potion's effect has triggered part-way through the animation. In that case, we can override the TearDownAutoUseItemOnAbilityActivated
event, and instead manually call MarkLocalItemExecuted
similarly to non-ability items.
To prevent make sure that you can't cancel one auto-use item with another, or with itself, we have some checks that prevent this. This includes checks that the item isn't already active, or its ability is on cooldown.
However, some items it may make sense to run in parallel, e.g. non-ability items that don't trigger animations or the like and just modify state. In these cases, we can loosen the restrictions by setting the AutoUseInParallel
flag in the item PDA's UseItemDetails
. If the flag is false, the item is considered "blocking", so other auto-use items can't be run whilst it is active.
NOTE: Auto-use items that trigger abilities can't be set to AutoUseInParallel
. This is because the ability system only allows one ability running at a time.
Since we enforce that you can't use an auto-use item if it's currently running, and that you can't use a "blocking" one if a different blocking item is in use, or if the required ability is in cooldown, we can end up in a situation where auto-use items don't trigger, if the system thinks an item is still running.
The following are some useful steps to debug why the subsequent auto-use items are being rejected:
Check for the ZombieUseItemCheck
in your logs:
We have a check that runs when you trigger the item. If one has been running for longer than expected, it'll give a warning, along the lines of the following:
LogJunoInventory: Warning: UJ_ItemExecutorBase::ZombieUseItemCheck: Auto-use item executor BP_ItemExecutor_Grow_C_0 (running ability: BP_GrowAbility_C_0) has been running for a long time (OnClient: 0). Did you forget to call MarkLocalItemExecuted?
Enter the command Log LogJunoInventory Verbose
This will enable verbose logs, including rejection reasons for auto-use items, e.g.
LogJunoInventory: Verbose: UJM_EquipmentComponent::CanAutoUseItem: Rejecting PDA_Item_Grow because Item BP_ItemExecutor_Grow_C_1 is already in use