PlaceAtMe - ObjectReference

From the CreationKit Wiki
Jump to navigation Jump to search

Member of: ObjectReference Script

Makes X new references of the passed in form, optionally forcing them to persist, and places them at our reference's location, returning the last one it created.

Syntax[edit | edit source]

ObjectReference Function PlaceAtMe(Form akFormToPlace, int aiCount = 1,
   bool abForcePersist = false, bool abInitiallyDisabled = false) native

Parameters[edit | edit source]

  • akFormToPlace: The base form to create references of.
    • Note: the akFormToPlace can be things such as MiscItem, Actor, ActorBase, etcetera, but it cannot be an ObjectReference
  • aiCount: How many references to make at once.
    • Default: 1
    • Caution: Only the last reference created is returned.
  • abForcePersist: True to force the created reference to be persistent.
    • Default: False
  • abInitiallyDisabled: True to force the reference to be initially disabled
    • Default: False
    • Caution: This is only applied to the last reference created.

Return Value[edit | edit source]

The last ObjectReference that was created. Or None if no references could be created for some reason.

Examples[edit | edit source]

; Place a new box at the target marker
ObjectReference newBox = TargetMarker.PlaceAtMe(BoxBase)


; Place two new boxes at the target marker
ObjectReference oneOfTheBoxes = TargetMarker.PlaceAtMe(BoxBase, 2)


; Place a horker at player. Use 0x<FormID>.
ObjectReference Horker = Game.GetPlayer().PlaceAtMe(Game.GetForm(0x00023ab1))


; Place a Rock at player.
Game.GetPlayer().PlaceAtMe(RockProperty)

Notes[edit | edit source]

  • If you want to place a leveled actor, you probably want PlaceActorAtMe - ObjectReference(use with caution).
  • A common mistake with PlaceAtMe is passing an object of type ObjectReference as its akFormToPlace parameter. Attempting to do so will result in this compilation error:
    type mismatch on parameter 1 (did you forget a cast?)

    This is the same error as you would see if you were to use an Actor as the first parameter of PlaceActorAtMe, which should be of type ActorBase.

    The first parameter of PlaceAtMe should be of type Form. If you need to get a Form from an ObjectReference, use the GetBaseObject function.

    ObjectReference Property MyObjectReference Auto
    Form MyBaseObject
    
    Event OnInit()
    	MyBaseObject = MyObjectReference.GetBaseObject()
    EndEvent
    
    ; ...
    	PlaceAtMe(MyBaseObject)
    ; ...
  • Objects no longer used should be disabled (through DisableNoWait or a similar function) and marked for deletion (through Delete) to prevent them from bloating the user's savegame.
  • Objects created through runtime scripting are not hooked up to physics events like OnTriggerEnter until the cell reloads if the object's base form does not already exist in the cell on cell load. [1] This can be worked around by calling Disable and then Enable on the object, which will immediately update the engine. Since non-physics events like OnInit function correctly, this can easily be rectified by re-enabling the object in OnInit on the spawned object.
  • As with MoveTo and SetPosition, objects created with this method will sometimes appear in odd angles, and it doesn't take in account for uneven terrain. This does not apply the actors. To correct their rotation, use SetAngle, with a 0 X coordinate, and the Y and Z coordinates being whatever you wish it to be.
  • Even if you set the object to be initially disabled, its OnLoad event will still fire, and then fire again when you decide to enable it.
  • Some forms, like MapMarker, cannot be created at run-time. Attempts to create them will fail silently and return None.

See Also[edit | edit source]