Skip to content

GetEntityModel() #4053

Description

@mtgtnt

What happened?

Found another possible OneSync regression.

I have been struggling with vehicles despawning immediately after being spawned with:

CreateVehicle(model, x, y, z, heading, true, true)

The vehicles could appear briefly and then disappear without DeleteVehicle or DeleteEntity being called.

I traced this to an old server-side entityCreating handler:

AddEventHandler("entityCreating", function(entity)
	local model = GetEntityModel(entity)
	if model == 0 then
		CancelEvent()
	end
end)

This handler existed for a long time without causing problems.
After updating FXServer artifacts when the major onesync memory change was implemented (or somewhere around there), GetEntityModel(entity) now intermittently returns 0 for entities created by legitimate connected players.

During one 25 minute race, the condition was triggered 78 times across 13 legitimate players.

Because CancelEvent() was called, those entities were silently rejected. This explains why the affected vehicles appeared and then disappeared without any DeleteVehicle/DeleteEntity diagnostics.

After commenting out CancelEvent(), the model-zero events continued occurring, but the vehicles were no longer rejected.

Expected behavior:

For a valid client-created network entity, GetEntityModel during entityCreating should return its model hash, as it did on the previously used artifact.

Actual behavior:

GetEntityModel intermittently returns 0 during entityCreating. The entity is owned by a valid player and, when not cancelled, continues creation normally.

If model data is no longer guaranteed to be available during entityCreating, please confirm whether this is an intentional behavior change.

I am currently on 30707

Expected result

For a valid client-created network entity, GetEntityModel during entityCreating should return its model hash, as it did on the previously used artifact.

Reproduction steps

  1. Start a server with OneSync enabled.
  2. From a client script, load a vehicle model and spawn it using CreateVehicle(..., true, true).
  3. On the server, monitor the entity using the entityCreating event.
  4. Call GetEntityModel(entity) inside entityCreating.
  5. Occasionally, it returns 0 for a legitimate player-created network vehicle.
  6. Calling CancelEvent() when the model is 0 causes the newly spawned vehicle to disappear without any DeleteVehicle or DeleteEntity call.
  7. Without CancelEvent(), the entity continues creating normally and its model becomes available afterward.

Importancy

There's a workaround

Area(s)

OneSync

Specific version(s)

FiveM artifacts when the major onesync memory change was implemented or somewhere around there. I was updating artifacts as they come out thinking it was there.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtriageNeeds a preliminary assessment to determine the urgency and required action

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions