Download

Operating on strings/Names and performance.

Many years ago when I took a php class, I was taught that operating on strings is quite expensive, or at the very least the most expensive of the alternatives - ints, enums etc. Comparing strings, switch on string should be avoided, I was taught.

How true is that today? I wonder because I’ve noticed that a few parts of UE seems to operate on strings such as “Set collision Profile Name”. Well, they are not Strings. They are Names. Are Names less expensive than Strings?

I ask this because I am attempting to create a system that sends messages throughout the system. For example a simple system would be pressing a button, that button sends a message to a box, which sends a message to a door to open. So the button opens the door. But then maybe the player can hack the box to make it send other messages when the button tells it that it has been pressed.

There will also be bigger systems, like flood fill-esque.

So can I use strings or names for this? Or should I stick to something else, probably Enums?

In UE4, we use names, which are LESS expensive than strings.
In general, if you are on a powerful PC/console, and you are not running a string every frame, I don’t think it matters as much.