PlaceAtMe - ObjectReference

From the CreationKit Wiki
Revision as of 21:07, 4 September 2018 by imported>DavidJCobb (→‎Parameters: Disassembly confirms that abInitiallyDisabled is only applied to the last created reference. However, abForcePersist is applied to all created references.)
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

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

Parameters

  • 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

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

Examples

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


; Place a 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

  • 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.
  • 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