Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity state is inaccessible on entity removal #3081

Open
bianchim opened this issue Jan 18, 2025 · 1 comment
Open

Entity state is inaccessible on entity removal #3081

bianchim opened this issue Jan 18, 2025 · 1 comment
Labels
bug ScRT: Lua Issues/PRs related to the Lua scripting runtime triage Needs a preliminary assessment to determine the urgency and required action

Comments

@bianchim
Copy link

What happened?

Since artifact 12160 and the changes in DeleteVehicle, it's impossible to get a vehicle state before its complete deletion.

On older artifacts you could still for a bit of time get an entity state on deletion, in order to have some actions on vehicle deletion for exemple :

AddEventHandler('entityRemoved', function(entity)
    if DoesEntityExist(vehicle.entity) then
        local State = Entity(EntityId).state
        -- do some stuff ...
    end
end)

Since artifact 1260, the DoesEntityExist always return false in this event, and the state is empty.

For scripting doing impound and garage functionality, this is a must have to be able to handle vehicle deletion and persistence correctly.

We would either need an event EntityRemoving similar to creating, or still get the old behavior on older artifacts.

Expected result

Getting access to vehicle data on deletion

Reproduction steps

  1. Add an event handler on 'entityRemoved', and try to get the vehicle state using Entity(EntityId).state in the function's body
  2. Remove an entity using the DeleteVehicle native
  3. the state is not accessible and the entity is indicated as removed by the DoesEntityExist native immediately, instead of having a grace period.

Importancy

Slight inconvenience

Area(s)

FiveM, ScRT: Lua

Specific version(s)

FiveM 12160 and newer

Additional information

No response

@bianchim bianchim added bug triage Needs a preliminary assessment to determine the urgency and required action labels Jan 18, 2025
@github-actions github-actions bot added the ScRT: Lua Issues/PRs related to the Lua scripting runtime label Jan 18, 2025
@AvarianKnight
Copy link
Contributor

You shouldn't really be checking DoesEntityExist in entityRemoved, the entity should always exist during the call as long as you're doing synchronous code.

DoesEntityExist will check if the entity is in a deleting or finalizing state and if it is it will return, I think it makes more sense to keep it the way it currently is as the proper use case this shouldn't let you access an entity that is deleting or finalizing a delete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ScRT: Lua Issues/PRs related to the Lua scripting runtime triage Needs a preliminary assessment to determine the urgency and required action
Projects
None yet
Development

No branches or pull requests

2 participants