Hey, i would like to hear your opinions, on which approach will yield better performance result
case 1: Set Transform
case 2: Set Location + Set Rotation
in both cases, the Scale is not affecting anything, and you can assume the operation happens in a big loop or tick event, so every bit of performance is important.
Why don´t you simply messure it? But my gut feeling tells me Transform will be faster (and no I won´t look at source, or messure it to figure it out for you ;P)
if somebody have tested it before me, it will be shorter before i do it myself
it will serve as a google search result for these who care about the topic, and they will get an answer (because i will post it anyway if nobody does in some time)
Can’t wait for it - very interesting what would be the result -
just don’t forget to make a large enough loop so the gap will be noticible and more precise.
And don’t use constant lications - since CPU may optimize it in L caches.
Do something like index multiply by something constant (don’t use randoms as well it may kill all the test by it’s own complexity)
Hmm… then make sure that nativization is off
Hard to say - it surely not optimizes the BPs but it could optimize the C++ core code under the hood - which is not a big deal so you seem to be right.
are you sure however that CPU does optimizations even on blueprints? they seem pretty unoptimized by nature as long as they don’t get nativized in the build
case 1: GetTransform -> SetTransform [-50 FPS]
case 2: GetLoc + GetRot -> SetTransform (break pin / make transform to combine loc+rot) [-55 FPS]
case 3: GetLoc -> SetLoc + GetRot -> SetRot [-56 FPS]
The First case clearly won. The difference is nearly 10% more performance when using GetTransform, rather than GetLoc + GetRot, even though it contains one more vector in it (scale)
**I did not test it in C++**
, but i think it will be the **opposite** there. i would love to hear if someone does it.
No, the result will be roughly the same… SetLocation has much more code and branches inside it (dealing woth physics/sweeps and what not). SetTransform is roughly straight forward.
I took a look in to the source again
SetLocation() will call a lot of functions and branches (where it takes current and relative transform in each and does some math on it),
and in the end it will call this function:
Which is quite big and also it recomputes the rotation again.
So:: even without continuing to look further in code:
SetLocation setting both location and rotation (While SetActorTransform is much much much narrower function)
bool AActor::SetActorTransform(const FTransform& NewTransform, bool bSweep, FHitResult* OutSweepHitResult, ETeleportType Teleport)
{
// we have seen this gets NAN from kismet, and would like to see if this
// happens, and if so, something else is giving NAN as output
if (RootComponent)
{
if (ensureMsgf(!NewTransform.ContainsNaN(), TEXT("SetActorTransform: Get NAN Transform data for %s: %s"), *GetNameSafe(this), *NewTransform.ToString()))
{
RootComponent->SetWorldTransform(NewTransform, bSweep, OutSweepHitResult, Teleport);
}
else
{
if (OutSweepHitResult)
{
*OutSweepHitResult = FHitResult();
}
}
return true;
}
if (OutSweepHitResult)
{
*OutSweepHitResult = FHitResult();
}
return false;
}
Of course. The FPS were given just for relative measuring rather than benchmarking. clearly the one with the best FPS is the one with the best benchmark