fivem icon indicating copy to clipboard operation
fivem copied to clipboard

tweak(gamestate/server): Apply routing bucket changes to child attachments

Open tens0rfl0w opened this issue 1 year ago • 9 comments

Goal of this PR

Changing the routing bucket of an entity does not update the routing buckets of possible attached child entities. This causes various problems, one of which is broken collision data for entities that get re-attached to other entities with the same handle.

How is this PR achieving the goal

Sync data is only parent-focused, so we have no info about possible child attachments. This makes it necessary to iterate through the server's entity list and traverse possible chained attachments to make sure we catch every possible attachment path to the root entity.

I tried to keep recursive calls as low as possible with tracking already traversed paths, which should also prevent cyclic attachments from causing infinite recursions.

https://github.com/user-attachments/assets/df8aaa42-ca78-4c2d-a568-47fb93fd3fd4

This PR applies to the following area(s)

FiveM, Server

Successfully tested on

Game builds: 3258

Platforms: Windows

Checklist

  • [x] Code compiles and has been tested successfully.
  • [x] Code explains itself well and/or is documented.
  • [x] My commit message explains what the changes do and what they are for.
  • [x] No extra compilation warnings are added by these changes.

Fixes issues

/

tens0rfl0w avatar Oct 07 '24 22:10 tens0rfl0w

Could be great to also change routing buckets of passagers when we change the routing bucket of a vehicle instead of iterate on them QoL

CeebDev avatar Oct 07 '24 23:10 CeebDev

Great news :) Any solution for non attached entities like pet ? or maybe vehicle or horse ? to be switched automatically as well ?

Identity-labs avatar Oct 08 '24 08:10 Identity-labs

Could be great to also change routing buckets of passagers when we change the routing bucket of a vehicle instead of iterate on them QoL

Yeah, this definitely could be added, though I'm not sure if this is a generally desired behavior. Would be great to get some additional feedback on this.

Great news :) Any solution for non attached entities like pet ? or maybe vehicle or horse ? to be switched automatically as well ?

Could you elaborate on what you mean with 'entities like pet'? Not sure If I got you right here, are you also referring to automatically applying bucket changes to vehicle passengers?

tens0rfl0w avatar Oct 08 '24 11:10 tens0rfl0w

Could be great to also change routing buckets of passagers when we change the routing bucket of a vehicle instead of iterate on them QoL

Yeah, this definitely could be added, though I'm not sure if this is a generally desired behavior. Would be great to get some additional feedback on this.

Well would it be desired behavior to set a vehicle into a bucket and all passengers fall out and the vehicle disappear? Logically thinking about it, setting a vehicle's bucket should set all players and entities inside said vehicle into the same bucket. If people wish to remove people from a vehicle plenty of methods exist that don't involve removing it from that player's existence.

I think its safe to do the same with vehicle and pax if not already done.

JnKTechstuff avatar Oct 08 '24 16:10 JnKTechstuff

Could you elaborate on what you mean with 'entities like pet'? Not sure If I got you right here, are you also referring to automatically applying bucket changes to vehicle passengers?

Today if you have peds following you, with relationship/range & co you have to remove the ped before changing bucket. Because ped will no longer have owner in original bucket and stay alone in this bucket.

May be add a native to tag entities to be linked to root entity, like that they are migrated in bucket when root entity is changing bucket same way as attached entity ?

Identity-labs avatar Oct 08 '24 20:10 Identity-labs

Thank you for the feedback!

This now also factors in vehicle occupants and applies bucket changes to those as well.

For anyone reviewing this: A possible short-path for checking for occupants would be to use the data in CVehicleGameStateNodeData, but this wouldn't factor in possible chained attachments of the occupant entity.

Today if you have peds following you, with relationship/range & co you have to remove the ped before changing bucket. Because ped will no longer have owner in original bucket and stay alone in this bucket.

This would be out-of-scope of this PR, as this only focuses on (chained) attachments/connections to the root entity. Checking for possible ped relations would make this not deterministic and therefore not possible to check this way.

tens0rfl0w avatar Oct 08 '24 20:10 tens0rfl0w

Could be great to also change routing buckets of passagers when we change the routing bucket of a vehicle instead of iterate on them QoL

There is scenarios where we want to change the routing bucket of the driver and not the passengers. The best option would be to let a way to chose.

Shinzuh avatar Oct 08 '24 23:10 Shinzuh

There is scenarios where we want to change the routing bucket of the driver and not the passengers. The best option would be to let a way to chose.

Give example of case where you only need to change bucket of vehicle but not passengers

CeebDev avatar Oct 09 '24 00:10 CeebDev

Thinking of it I don't have any special exemples for my use case but the backward compatibilty scare me a bit. Scripts weren't expecting that a change of a bucket for a player could change it for other players too. A bool to activate this new comportment seems to be the strict necessary

Shinzuh avatar Oct 09 '24 13:10 Shinzuh

I can't think of any scripts that would be designed to expect the players to magically teleport out of the player's vehicle by changing the bucket?

I can think of more use cases in which automatically switching the bucket for passengers / driver when changing the bucket of the vehicle they are in, is preferred /desired.

Gravxd avatar Feb 18 '25 23:02 Gravxd

Thinking of it I don't have any special exemples for my use case but the backward compatibilty scare me a bit. Scripts weren't expecting that a change of a bucket for a player could change it for other players too. A bool to activate this new comportment seems to be the strict necessary

Also keep in mind the original proposal idea was to change to change the passenger's bucket (if any passengers) when the vehicle entity's bucket was changed, not the driver. So i really couldn't see any unintended behaviour as if you are modifying a vehicle's bucket, youd probably want to keep the driver.

Gravxd avatar Feb 18 '25 23:02 Gravxd

Regarding entity bucket changes and related entities, I would follow an approach similar to SetEntityCoords. For example, when changing a vehicle's coordinates, all passengers should remain inside. However, if we change a passenger's coordinates, they should be teleported out of the vehicle. The same logic applies to attached entities.

draobrehtom avatar Feb 19 '25 14:02 draobrehtom

Any update on this ? If you want full backward compat, add a convar

CeebDev avatar Mar 16 '25 04:03 CeebDev

Could be great to also change routing buckets of passagers when we change the routing bucket of a vehicle instead of iterate on them QoL

Yeah, this definitely could be added, though I'm not sure if this is a generally desired behavior. Would be great to get some additional feedback on this.

An example use case of this would be if you had some sort of garage system, like GTA:O, where players can get in to a vehicle and drive out, it would be useful to have the passengers change buckets along with the vehicle otherwise they'll be kicked out when transferring buckets (leaving the garage) since the vehicle won't exist for them for x amount of time until the bucket swap is complete.

jellyton255 avatar Mar 16 '25 04:03 jellyton255

This is still important, why is this waiting this long for implementation...

BennoArnautovic avatar Nov 20 '25 03:11 BennoArnautovic