Can we use one of these to avoid casting

I think casting is an expensive operation (mentioned by tastysnak in another post), I was wondering if using one of these functions and then comparing with text value is a good alternative for it?

Could you provide context please?

Oh sorry, I have a collision detection box as a blueprint and I want to check if the overlapped actor is the player character.
In the course, we were taught to achieve that via casting:


But in one of the post in the forum it was mentioned that casting is expensive operation so I was wondering if there are more efficient alternatives.

I see we have these Get Object/DisplayName/Class methods, so wanted to know if we can use those to figure out if overlapped actor is of a certain pawn class?

The problem with that is that it won’t scale well and now you’re comparing strings, assuming casting in blueprint is the same as C++ then that’s not strictly better.

I think “casting is bad for performance” is drilled in to hard to people, yeah, don’t be silly with it but you shouldn’t be scared to ever use it. It’s most likely not going to make a noticeable difference a lot of the time.

Ok if casting performance is not really a concern then I will stick with that. Thanks.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms