Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We need a stable vehicle identifier that works for both NPC and player owned vehicles. vehicleid already represents player owned vehicles, so overloading it could cause issues with scripts relying on this behavior. netId would not be stable for persisted vehicles, which have their entities deleted and spawned.
Therefore this PR is introducing a sessionId, which will be incremented starting by 1 to guarantee uniqueness. This will be set via a new export CreateSessionId on the vehicle's state bag, which acquires a lock to guarantee that no two vehicles are assigned the same id. This will be persisted during vehicle persistence.
Also sneaking in a fix to persist vehicleid during vehicle persistence as I realize we never did that before.
While this is being introduced for vehicles, it is being introduced as a generic feature that could be used for any entity. This may prove useful for other applications which want a unique id to reference when those entities may be deleted and re-created.