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#
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
)
| Name | Type | Default | Description |
|---|---|---|---|
location |
Vector |
(0,100,100) |
Spawn position |
rotation |
Quat |
(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
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)
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)
local bagActor = npc:AddStaticMeshAttached("bag", BagMesh, "spine_03")
RemoveStaticMeshAttached#
Removes a previously attached mesh by ID
- id:
string— the attachment ID passed toAddStaticMeshAttached - returns:
boolean—trueif an attachment was removed
local bRemoved = npc:RemoveStaticMeshAttached("bag")
RemoveAllStaticMeshesAttached#
Removes all attached meshes from the character
npc:RemoveAllStaticMeshesAttached()
SetRagdollMode#
Toggles ragdoll physics on or off
- bEnable:
boolean—trueto enable ragdoll,falseto disable
npc:SetRagdollMode(true)
SetMesh#
Overrides the character’s skeletal mesh
- mesh:
USkeletalMesh— the new skeletal mesh
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
npc:SetName("Guard A")
SetTeam#
Assigns a simple team tag on the wrapper
- team:
any— team identifier
npc:SetTeam("Hostile")
GetPawn#
Returns the underlying ACharacter actor. (may be nil until the async spawn finishes)
- returns:
ACharacter | nil
local pawn = npc:GetPawn()
GetMesh#
Returns the name of the currently assigned skeletal mesh
- returns:
string | nil
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
local transform = npc:GetBoneTransform("spine_03")
IsInRagdollMode#
Returns true if ragdoll physics are currently active
- returns:
boolean
if npc:IsInRagdollMode() then ...