The base class for everything that exists in the world on the client.

An Entity is a thin, allocation-cheap wrapper around a game handle: it stores the integer and nothing else, so constructing one is free and two wrappers around the same handle are interchangeable. Properties read through to the natives on every access rather than caching, which is what you want — the game moves entities constantly.

var vehicle = LocalPlayer.ped().currentVehicle;
if (vehicle != null && vehicle.exists) {
    vehicle.coords = vehicle.coords + Vector3.up() * 3.0;
}

Handles are client-local and are recycled by the game. Never store one across a resource restart, and never send one over the network — send netId instead, which is stable across clients.

Static methods

staticfromHandle(handle:Int):Entity

Wraps a handle in the most specific class available — Ped, Vehicle or Prop — based on what the game says it is. Returns null for a handle that doesn't exist.

staticfromNetId(netId:Int):Entity

Resolves a network ID to a local entity, or null if the entity isn't streamed in on this client.

Network IDs are the only entity reference that means the same thing on every machine, so this is how a server event's payload becomes a usable handle.

Constructor

new(handle:Int)

Variables

alpha:Int

Opacity from 0 (invisible) to 255.

read onlyattachedTo:Entity

The entity this one is attached to, or null.

write onlycollision:Bool

read onlyexists:Bool

read onlyforwardVector:Vector3

The unit vector the entity faces.

write onlyfrozen:Bool

Whether the entity is pinned in place. Write-only — the game exposes no getter.

finalhandle:Int

The raw game handle.

read onlyhasControl:Bool

Whether this client currently owns the entity. Only the owner may modify a networked entity and have the change replicate.

heading:Float

Yaw only, in degrees — 0 faces north.

health:Int

read onlyheightAboveGround:Float

write onlyinvincible:Bool

read onlyisAttached:Bool

read onlyisDead:Bool

read onlyisNetworked:Bool

read onlymaxHealth:Int

read onlymodel:Int

The model hash this entity was created from.

read onlynetId:Int

The network ID, stable across all clients — the value to send in events. Returns 0 for a purely local entity.

write onlyoutline:Bool

Draws the game's selection outline around the entity.

rotation:Vector3

Rotation in degrees as (pitch, roll, yaw).

read onlyspeed:Float

Current speed in metres per second. Multiply by 3.6 for km/h, 2.237 for mph.

read onlystate:StateBag

The entity's replicated state bag. Reads work on any client; writes only replicate from the server.

read onlytype:EntityType

visible:Bool

Methods

@:value({ collision : false, bone : 0 })attachTo(target:Entity, offset:Vector3, rotation:Vector3, bone:Int = 0, collision:Bool = false):Void

Attaches this entity to target, offset from one of its bones.

Parameters:

bone

Bone index on the target; 0 attaches to its origin.

collision

Whether the two keep colliding with each other.

delete():Void

Deletes the entity.

Requires ownership: on a networked entity this silently does nothing unless requestControl() succeeded first.

@:value({ collision : true, keepVelocity : true })inlinedetach(keepVelocity:Bool = true, collision:Bool = true):Void

inlinedistanceTo(point:Vector3):Float

inlinedistanceToEntity(other:Entity):Float

@:value({ flags : 17 })inlinehasClearLineOfSightTo(other:Entity, flags:Int = 17):Bool

Whether nothing solid sits between this entity and other.

inlinemarkAsNoLongerNeeded():Void

Releases the entity back to the game, which may then despawn it.

inlineoffsetInWorldCoords(offset:Vector3):Vector3

Converts a position expressed in the entity's own frame into world space.

@:value({ timeoutMs : 1000 })requestControl(timeoutMs:Int = 1000):Bool

Asks the server for ownership and waits for it, returning whether it was granted before timeoutMs elapsed.

Every write to a networked entity you don't own is silently reverted by its real owner, so call this first:

if (vehicle.requestControl()) vehicle.repair();

Must be called from inside a coroutine. Ownership can be lost again at any moment, so keep the work that follows short.

@:value({ grabFromOtherScript : true })inlinesetAsMission(grabFromOtherScript:Bool = true):Void

Claims the entity for this script, so the game's population manager won't clean it up while you're using it.

teleport(position:Vector3, ?heading:Float):Void

Moves the entity without the game's usual "find a valid spot" fixups — no ground snapping, no pushing out of collision. Use it when you have already worked out exactly where the entity belongs.

toString():String

inlineworldToLocal(worldPosition:Vector3):Vector3

The inverse of offsetInWorldCoords: world space into the entity's frame.