Very Slow Hit Result Struct in Loop.

I noticed that connecting directly from a “ForEachLoop” can be very slow. Especially if they are in a struct array.

My test went like this:
You will notice that there is a MultiThreadedNode. Of course it’s not original and I added it myself with c++. I needed it to measure time.

I have created 2 structs with an array. Since I had severe problems with the “HitResult”, I specifically used this and an integer array as a counter candidate.

I fed both with a loop.

Then I had both read out individually.
The “Branch” had to be there, otherwise the struct will be ignored.

The HitResult takes 14 seconds as an array when it is linked to a struct array. That was exactly my problem, why the game kept freezing.
image

Now I thought it was due to the “ForEachLoop”. I edited this macro and put the “Length” in a variable. Unfortunately, this only resulted in success without “Branch” in my Script. So, be careful not to use “Length” in a loop! This slows down your speed.

I later came up with the idea of simply putting the HitResult array in a variable. That gave a real boost. From 14 seconds to 0.03 seconds. That’s a big difference.

Why?

I uploaded my blueprint to BlueprintUE.

1 Like