Is casting to a BP a big performance hit?

HI!

For some reason I thought I saw or heard on the Unreal 4 twitch streams that doing the whole “Cast to BP” node is or can be a big performance hit and should be avoided. Is this true? Or is “Cast to BP” just fine to use whenever? Thank you!

Pretty cheap. Can’t really do much without casting.

You could do pure casting, it’s faster

For do pure casting, just right click on the node and select “pure casting” or “convert to pure”… (you dont have the fail output) (still it can fail, but you it is not possible to provide the code to handle that case.

Okay awesome. Yeah I’ve been trying to avoid it for whatever reason and it’s been making my life quite difficult. Thank you two!

Curious to see how casting stacks up against “Get All Actors Of Class”- I assume casting is cheaper than this node, but often when I’m trying to call a custom event from another blueprint, it seems as though it only is possible using the “Get All Actors Of Class” node.

There is a thread around here somewhere where someone did a massive performance test on casting and found it as fast as using any given blueprint node. You would have to do lots of casting in a very short amount of time to see an effect, but the same goes for using any blueprint node.

You should really only need to use it once so you can get a reference and save that to a variable. Then just reuse the variable to cast to the object.

Get all actors of class should be pretty quick anyway, unless you are doing it a lot in a very short amount of time. Given it fills an array and then you have to access the array it is going to be slower than a straight up cast using a variable though.

1 Like

I would imagine the performance of casting would be quite a bit more predictable since you have no real assurance how many actors would need to be evaluated when calling “get all actors o class” at runtime.