x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[performanсe] SetTransform vs SetLoc+SetRot

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.

Thank you in advance :)

Product Version: UE 4.16
Tags:
more ▼

asked Sep 24 '17 at 10:19 PM in Blueprint Scripting

avatar image

Arty-McLabin
868 19 41 61

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

SetTransform() is faster in blueprints.

I have run for loops of 8000 iterations per tick:

 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.
more ▼

answered Nov 26 '17 at 10:31 PM

avatar image

Arty-McLabin
868 19 41 61

avatar image ColdSteel48 Nov 26 '17 at 10:58 PM

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.

avatar image Arty-McLabin Nov 27 '17 at 11:15 AM

interesting, SetTransform has sweep and teleport too though, are you sure?

avatar image ColdSteel48 Nov 27 '17 at 04:14 PM

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:

 bool USceneComponent::InternalSetWorldLocationAndRotation(FVector NewLocation, const FQuat& RotationQuat, bool bNoPhysics, ETeleportType Teleport)

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;
 }




avatar image ColdSteel48 Nov 27 '17 at 04:18 PM

So basically from inspecting the Source:

SetLocation is intended for movement of the object While SetTramsform intended to just copy the Transform without too much things inside.

avatar image ColdSteel48 Nov 27 '17 at 06:43 PM

BTW FPS is not applicable to a measuring! The only thing cappable is a time.

avatar image Arty-McLabin Nov 27 '17 at 10:03 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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)

more ▼

answered Sep 29 '17 at 06:58 PM

avatar image

Nachtmahr
6.9k 143 26 172

avatar image Arty-McLabin Sep 29 '17 at 10:20 PM

two reasons:

  1. if somebody have tested it before me, it will be shorter before i do it myself

  2. 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)

:)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I took a quick look in to the sources it seems like setting the transform is much faster.

Transform just copies and sets the values.

SetActorLocation alone does more things - It seems like it tries to simulate movement does various overlap and collision checks.

more ▼

answered Nov 11 '17 at 04:06 PM

avatar image

ColdSteel48
527 6 18 23

avatar image Arty-McLabin Nov 11 '17 at 04:24 PM

it sounds very strange. i will soon make a test and post it here

avatar image ColdSteel48 Nov 11 '17 at 04:29 PM

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)

avatar image Arty-McLabin Nov 11 '17 at 05:23 PM

thanks for the tips.
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

avatar image ColdSteel48 Nov 11 '17 at 05:26 PM

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.

avatar image ColdSteel48 Nov 11 '17 at 09:50 PM

So, do you get any results?

avatar image Arty-McLabin Nov 11 '17 at 10:32 PM

i am not available in the next few days, but i will test is asap :]

avatar image Arty-McLabin Nov 26 '17 at 10:33 PM

finally did it, you can see the results in my answer here :]

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question