Optimizing suspension raycasts for multiple vehicles
danielkrakowiak opened this issue · 0 comments
Hi again,
following the PhysX docs about vehicles and the section about "Level of Detail" I'm trying to update only some of my vehicles in a single frame. I'm modifying FPhysXVehicleManager in UE4 to achieve that optimization. To simplify, let's focus on suspension raycasts. I'm using the last parameter in PxVehicleUpdate::suspensionRaycasts - const bool vehiclesToRaycast* to pass false for vehicles which should not be updated.
However I'm confused what to pass to vehicles and sceneQueryResults. Should those arrays only contain vehicles to update or all of my vehicles? Because inside PxVehicleUpdate::suspensionRaycasts all of the sceneQueryResults are reset (hasBlock = false). In game, vehicles appear to fall down every fraction of a second, like if update of some vehicles was causing a raycast-data reset for the ones which weren't updated.
What's the point of param vehiclesToRaycast then if I'm supposed to manage those arrays myself?
It's especially frustrating as sceneQueryResults contains the actual data (not pointers) that seems to be used by PxVehicleUpdates. So managing any temporary arrays is very confusing if those items are still pointed by various internal PhysX structs and used a few frames later. I can't understand the way it's supposed to work and the way I'm supposed to manage those arrays/temporaries. Any help and clarifications would be very helpful.
Also, we're assuming that vehicles may have arbitrary update rate and I can't just process first/second half of the array.
Ok, it seems that sceneQueryResults is a temporary by design and raycast results are copied from it to other structs during the vehicle update. So at least one vehicle update needs to follow suspension raycast before sceneQueryResults can be overwritten. It's actually written in the comments to PxVehicleUpdate::suspensionRaycasts, but I missed it.