Skip to content

ContainerInteraction ​

Inherits: InteractableObjectInteraction < Interaction < Resource

Container interaction - manages inventory storage in world objects Uses InteractableObject's InventoryComponent (created if this interaction is present)

Properties ​

Dictionaryinventory{ ... }
intmax_slots20
InventoryStyleinventory_stylenull
intloot_table_id
boolauto_close_enabledtrue
floatauto_close_distance4.0
Stringclosed_animation"closed"
Stringlocked_animation"locked"
Stringopen_animation"open"
SFXSelectioncontainer_open_sound
SFXSelectioncontainer_close_sound
SFXSelectioncontainer_locked_sound

Variables ​

InventoryComponentinventory_data
ContainerStatecurrent_container_stateContainerState.CLOSED_UNLOCKED
Entityopening_entitynull
Timerdistance_check_timer

Methods ​

boolrequires_inventory_component()
voidsetup_for_interactable_objects( interactable: InteractableObject )
Array[LootRule]get_legacy_loot_rules()
boolcan_interact( player: Player )
voidstart_interaction( player: Player )
voidend_interaction()
Stringget_interaction_prompt()
voidchange_container_state( new_state: ContainerState, interacting_entity: Entity = null )
voidon_object_destroyed()
voidrefresh_after_load()
voidon_unlocked()
voidon_locked_reaction()
InventoryComponentget_inventory()
boolis_empty()
voidforce_open()
voidforce_close()
Dictionarysave_state()
voidload_state( state: Dictionary )
voidcleanup()

Signals ​

container_opened( entity: Entity ) ​

Emitted when an entity opens the container.

container_closed( entity: Entity ) ​

Emitted when the container is closed.

Enumerations ​

enum ContainerState ​

The states of a container: closed and unlocked, closed and locked, open, or destroyed.

  • CLOSED_UNLOCKED = 0 - Container is closed and can be opened
  • CLOSED_LOCKED = 1 - Container is closed and locked
  • OPEN = 2 - Container is open and accessible
  • DESTROYED = 3 - Container is destroyed and inaccessible

Property descriptions ​

Container Setup

Dictionary inventory ​

Dictionary of inventory items and currency for this container Format: { "items": { item_id: quantity }, "currency": { currency_name: amount } }

int max_slots = 20 ​

Maximum number of inventory slots

InventoryStyle inventory_style = null ​

The rules of this container's bag (space, weight). Empty = the style of the containers of the Gameplay Config. In slots mode Max slots is the number of slots

Loot Generation

int loot_table_id ​

Loot table to generate items from (overrides definition loot_table if set)

Auto-Close

bool auto_close_enabled = true ​

Whether container auto-closes when opener moves away

float auto_close_distance = 4.0 ​

Distance at which container auto-closes

Animations

String closed_animation = "closed" ​

The animation of the container when it is closed.

String locked_animation = "locked" ​

The animation of the container when it is locked.

String open_animation = "open" ​

The animation of the container when it opens.

Audio

SFXSelection container_open_sound ​

The sound of the container opening.

SFXSelection container_close_sound ​

The sound of the container closing.

SFXSelection container_locked_sound ​

The sound of trying a locked container.

Variable descriptions ​

InventoryComponent inventory_data ​

The inventory of the container: what it holds.

ContainerState current_container_state = ContainerState.CLOSED_UNLOCKED ​

The state of the container now.

Entity opening_entity = null ​

The entity that has the container open now.

Timer distance_check_timer ​

The timer that closes the container when the entity that opened it walks away.

Method descriptions ​

bool requires_inventory_component() ​

Tell InteractableObject we need an InventoryComponent

void setup_for_interactable_objects( interactable: InteractableObject ) ​

Sets the container up on its object: finds the nodes it needs and applies its starting state.

Array[LootRule] get_legacy_loot_rules() ​

The loot rules the older settings of this container make: its fixed contents and its loot table, both rolled when the container is set up

bool can_interact( player: Player ) ​

Can the player use the container now (in range, the object is not broken, the requirements are met)?

void start_interaction( player: Player ) ​

The player uses the container.

void end_interaction() ​

Does nothing: a container stays open after the interaction ends.

String get_interaction_prompt() ​

The text of the prompt above the object for its state now ("Open", "Climb" ...).

void change_container_state( new_state: ContainerState, interacting_entity: Entity = null ) ​

Puts the container in a state (opening it, locking it ...) and plays its animation and sound.

void on_object_destroyed() ​

Called when the object is destroyed. A container that still holds something stays lootable, like a corpse.

void refresh_after_load() ​

After a load: a destroyed container with loot is lootable, an empty one is destroyed for good

void on_unlocked() ​

Called when the object is unlocked.

void on_locked_reaction() ​

Called when someone tries the object while it is locked: plays the locked sound and animation.

InventoryComponent get_inventory() ​

The inventory of the container.

bool is_empty() ​

Is the container empty?

void force_open() ​

Opens the container without a player (a script or an event). Not when it is destroyed.

void force_close() ​

Closes the container without a player.

Dictionary save_state() ​

The state of the container for a save.

void load_state( state: Dictionary ) ​

Restores the state of the container from a save.

void cleanup() ​

Gives its timers back and clears what it holds (the object is going away).