PointerValueIntInitialized not working with __data (table type)

-- This model is build 2372 only, so might have to change this
local model = `vw_prop_vw_luckywheel_02a`
RequestModel(model)

while not HasModelLoaded(model) do
    Citizen.Wait(0)
end

local obj = CreateObject(model, _wheelPos, false, false, true)
local entity = Entity(obj)
DeleteObject(entity)
-- Throws error: bad argument #1 to '_ii' (number expected, got table)

The above example shows the error.

The __data table entry only gets checked for normal values, but PointerValueIntInitialized doesn’t support this behavior, so any native using the pointer value doesn’t work with the table type.

Manually calling DeleteObject(entity.__data) is a temp workaround so a minor issue, but still an issue.

Entity(obj) doesn’t do what you’re thinking it does, it’s used for state bags.

See: fivem/scheduler.lua at a91087790ee87142a721fe1ae0aef972729d7e8a · citizenfx/fivem · GitHub

Try passing the actual object that you already declared.

local obj = CreateObject(model, _wheelPos, false, false, true)
DeleteObject(obj)

Yeah, and it can also be used for this.

I’m confused about how that would work?

Internally FiveM gets the __data entry, the Entity function stores the handle of the object in this entry.

So for ie. SetEntityRotation would work by just passing in a table created by the entity function.

See: LuaScriptNatives.cpp#L108 there you can see the PushTable function which tries to get a valid value from the __data entry, but for PointerValueIntInitialized this doesn’t get called unfortunately.

But the pointer values don’t work for this.