I’m making a game where I constantly add and remove static mesh components. To be more efficient I’d like to instead reuse ‘deleted’ instances by updating the transform. Currently the BatchUpdateInstancesTransforms method seems like it only updates consecutive indices. I’d like to be able to update the transforms of specific indices, say indices 1, 5, 12.
You can access the array of instance transforms directly - a routine like you want should be easy to write - it just won’t be quite as fast as a tight loop through consecutive indexes (you’re reading memory to get the index and then the index transform as well so two memory lookups - plus they’re not guaranteed to be cached in the CPU if they’re not consecutive so there may be multiple cache invalidations). If you’re only moving a small number of instances it won’t be noticable though…
If you’re looping somewhere to create those update lists, it will be more efficient just to get the pointer to the instance transforms and update them there rather than create the lists, pass them through and then have that routine loop through them again - if they’re small lists though then it’s not going to make that much difference, but it does when you’re handling large amounts of transforms.
Have a look at the code behind UInstancedStaticMeshComponent::BatchUpdateInstancesTransformsInternal()
UInstancedStaticMeshComponent::UpdateInstances()