Background for Skyrim SE
Member of the ObjectReference script
eventOnContainerChanged(ObjectReferenceakNewContainer, ObjectReferenceakOldContainer)

Description

Wiki Description

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

Documentation Comment

Event received when this object enters, exits, or changes containers


Caveats

CK Wiki - Notes

  • Once an object has been added to a container it is no longer valid to call functions on it. Functions on self 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.
  • This event should only be relied upon for single objects. Moving stacked objects or objects from a stack will not always cause the event to fire. See this thread on the official Creation Kit forum for more information.

Parameters

  1. ObjectReferenceakNewContainer

    CK Wiki Description

    The container this object is entering. If this is None, the object was dropped.

  2. ObjectReferenceakOldContainer

    CK Wiki Description

    The container this object just left. If this is None, the object was picked up.


Examples

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

Auto-Generated Example

Scriptname MyCoolScript extends ObjectReference

event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
    Debug.trace("Event received - OnContainerChanged: akNewContainer = " + akNewContainer + " akOldContainer = " + akOldContainer)
endEvent

Related Pages


Additional References

View this event’s page on the Skyrim Creation Kit Wiki

Some data provided by the Skyrim Creation Kit Wiki. Licensed under the Creative Commons Attribution-ShareAlike license.