Hi!
I’m a beginner dev and I’m wondering about the costs of storing and using Enum vs StaticClass/TSubclassOf.
For instance, this would be my base Pickup class.
class PROJECT_API APickupBase : public AActor
And this would be a Pickup type that inherits from that.
class PROJECT_API APickupType1: public APickupBase
Alright, so now I want to store that type in many, many different places in my project.
The number of pickups types are limited, so would I save any resource at all by using Enums instead (below) while storing that data (and then using it), or would it just add unnecessary calls to a dict that translates the Enum into the StaticClass?
Enum example:
UENUM()
enum class EPickupType : int16
{
None = 0 UMETA(DisplayName = "[INVALID]"),
Type1 = 1
};
EPickupType PickupType;
With a dict somewhere for when I need to translate it to instantiate the pickup:
const static TMap<EPickupType, TSubclassOf<APickupBase>> PickupTypeToClassMap = {
{EPickupType::Type1, APickupType1::StaticClass()}
};
Vs a straight:
TSubclassOf<APickupBase> PickupType;
I don’t need to use the TSubclassOf/StaticClass in all places I store the pickup type, that’s the major reason that led me to believe Enums might be cheaper here.
However, how much cheaper is it, really? Is it worth doing things this way at all? I mean, if all StaticClass calls return the very same UClass object as reference every time it’s called for the same class (and TSubclassOf stores it as a reference/pointer), it’s a single reference, so it wouldn’t be too costly. Except maybe when I’m comparing values, in which case Enums is probably cheaper?
So, help please?