OnContainerChanged - ObjectReference

From the Fallout4 CreationKit Wiki
Revision as of 02:51, 19 December 2021 by Rux616 (talk | contribs) (Added note about OnContainerChanged event still being fired if an item was removed with RemoteItem() with a FormList or Keyword argument.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Member of: ObjectReference Script

Event called when the object reference enters/leaves/moves between containers.

Syntax[edit | edit source]

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)

Parameters[edit | edit source]

  • akNewContainer: The container this object is entering. If this is None, the object was dropped.
  • akOldContainer: The container this object just left. If this is None, the object was picked up.

Examples[edit | edit source]

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
  if akOldContainer && !akNewContainer
    Debug.Trace("We have been dropped!")
  elseif akNewContainer && !akOldContainer
    Debug.Trace("We have been picked up!")
  else
    Debug.Trace("We have switched containers!")
  endIf
endEvent


Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
  if akNewContainer == Game.GetPlayer()
    Debug.Trace("I just got put in the player's inventory!")
  endIf
endEvent

Notes[edit | edit source]

  • Once an object has been added to a container it ceases to exist in most cases. Most functions (except those that are inventory-safe) will fail to run with an error.
  • Reminder: If you call RemoveItem() on an object and don't give it a destination container it is destroyed... such destroyed objects won't run an OnContainerChanged event. However, if an item is destroyed by RemoveItem() being called with a FormList or Keyword argument, the OnContainerChanged event will still be fired.

See Also[edit | edit source]