What is the most efficient way to set transforms in a hierarchy

I am some procedural animation that sets the localRotation, localTranslation of each bone on every frame. When I profile, I see that setting localRotation/Translation is an expensive operation, presumably because it is keeping all of the transforms in the hierarchy in sync (updating the localToWorld etc...).

So I am looking for the best way to update the bone transforms in a hierarchy. Ideally, I would like to set all of the local position/rotations without it updating any of the derivative transforms (i.e. localToWorld, and the localToWorld transforms of the children), and then have the derivative transforms updated accordingly when I am done. Is detaching the bones from the hierarchy, doing the update and then re-attaching them a reasonable option? Or alternatively, is there a method of Transform or GameObject that has the desired effect?



In the absence of any concrete information, my hunch would be that UT engineers have probably already put significant effort into ensuring that the transform hierarchy system already works in the most optimal way possible - probably much more so than you would feasibly have time for! - and any attempt to further optimise it by manipulating the hierarchy at runtime would probably only drag the speed down.

However, I'd be interested to hear the results of any performance tests which compare your suggested methods, or real info from UT engineers on the matter.

This is a partial answer to my original question...

  1. Removing all of the transforms from the hierarchy, setting their respective local position/orientation and then creating the hierarchy again, doesn't work. Indeed, it makes perfect sense that it wouldn't work.

  2. In my case, it is worth checking for equality before changing the position/rotation of a transform in a hierarchy because it is expensive to set the local position/rotation in a deep bone hierarchy. In my case, I was able to reduce the overall cost by 1/3 or more.

  3. Just to be clear, my original question wasn't suggesting that the update of transforms wasn't being done in an efficient manner. Rather, that the decision of "when to update" is different when the user is changing a single transform (immediately after the change), or when you know (because the user has told you) that the user is changing a batch of transforms at one time (after the batch of changes). Applying a keyframe from a clip of animation is an example of the latter.

If you don't want to mess with the hierarchy, have a look at the question here, and the posted answers:

Solutions to make characters stay perfectly on platforms