Skip to main content

HPawn

HPawn creates a nonโ€‘player character (NPC) actor with helper functions for playing animations, attaching meshes, toggling ragdoll, and querying state. Ideal for passive/ambient NPCs, enemies, or scripted actors

/// tip HPawn is an Actor so it inherits all functions from Actor ///

Constructorโ€‹

Example
local npc = HPawn(
Vector(0, 0, 100), -- location
Rotator(0, 0, 0), -- rotation (Rotator or Quat accepted)
function(SpawnedPawn) -- optional callback when NPC is created
print("Spawned:", SpawnedPawn)
end
)
NameTypeDefaultDescription
locationVector(0,100,100)Spawn position
rotationQuat(0,0,0,1)Spawn orientation

Functionsโ€‹

PlayAnimationโ€‹

Plays a montage animation on the character

  • montage: UAnimMontage โ€” montage to play
  • playRate: number โ€” playback speed multiplier (e.g., 1.0)
  • startSection: string | nil โ€” optional section name to start from
Example
npc:PlayAnimation(MyMontage, 1.0, "StartSection")

StopAnimationโ€‹

Stops an active montage with an optional blend-out

  • blendOutTime: number โ€” time to blend out (seconds)
  • montage: UAnimMontage | nil โ€” specific montage to stop (nil = any)
Example
npc:StopAnimation(0.25, MyMontage)

AddStaticMeshAttachedโ€‹

Spawns a AStaticMeshActor, attaches it to a bone/socket, and tracks it by ID. Replaces any prior attachment with the same ID. Default socket is "hand_l"

  • id: string โ€” unique attachment ID
  • staticMesh: UStaticMesh โ€” mesh to attach
  • socketName: string โ€” bone/socket (default "hand_l")
  • returns: AStaticMeshActor | nil โ€” the spawned actor (nil on failure)
Example
local bagActor = npc:AddStaticMeshAttached("bag", BagMesh, "spine_03")

RemoveStaticMeshAttachedโ€‹

Removes a previously attached mesh by ID

  • id: string โ€” the attachment ID passed to AddStaticMeshAttached
  • returns: boolean โ€” true if an attachment was removed
Example
local bRemoved = npc:RemoveStaticMeshAttached("bag")

RemoveAllStaticMeshesAttachedโ€‹

Removes all attached meshes from the character

Example
npc:RemoveAllStaticMeshesAttached()

SetRagdollModeโ€‹

Toggles ragdoll physics on or off

  • bEnable: boolean โ€” true to enable ragdoll, false to disable
Example
npc:SetRagdollMode(true)

SetMeshโ€‹

Overrides the characterโ€™s skeletal mesh

  • mesh: USkeletalMesh โ€” the new skeletal mesh
Example
npc:SetMesh(UE.UObject.Load("/Game/MyMeshes/MyCustomMesh.MyCustomMesh"))

SetNameโ€‹

Sets a display/name for the pawn (implementation placeholder calls into pawn)

  • name: string โ€” desired name
Example
npc:SetName("Guard A")

SetTeamโ€‹

Assigns a simple team tag on the wrapper

  • team: any โ€” team identifier
Example
npc:SetTeam("Hostile")

GetPawnโ€‹

Returns the underlying ACharacter actor. (may be nil until the async spawn finishes)

  • returns: ACharacter | nil
Example
local pawn = npc:GetPawn()

GetMeshโ€‹

Returns the name of the currently assigned skeletal mesh

  • returns: string | nil
Example
print("Mesh name:", npc:GetMesh() or "none")

GetBoneTransformโ€‹

Returns a FTransform for a bone name (e.g., "hand_r")

  • boneName: string โ€” the bone/socket name
  • returns: Transform | nil
Example
local transform = npc:GetBoneTransform("spine_03")

IsInRagdollModeโ€‹

Returns true if ragdoll physics are currently active

  • returns: boolean
Example
if npc:IsInRagdollMode() then ...
โœจ