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