Download

Is it possible / good practice to declare multiple members using a single UPROPERTY?

I’m new to UE4 and have a class that has multiple members that are all floats, and have the exact same UPROPERTY. I was wondering if it would be possible to have them declared all under the same UPROPERTY in order to make it look nicer, and if so, would that be a bad practice? If its not possible, or a bad practice, why would it be?

For example, turning


    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Camera)
        float CameraHeightAngle;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Camera)
        float CameraHeightAngleMax;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Camera)
        float CameraHeightAngleMin;

into

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Camera)
    float CameraHeightAngle, CameraHeightAngleMax, CameraHeightAngleMin;

I’ve tried looking online but the only thing I have found was, Declare multiple class members in-line with UPROPERTY? - Unreal Engine Forums, which just says not to do it. Sorry if this has (and most likely has) been asked many times.

You should probably think more about the person(designer?) using your properties than how it looks in the code. Consider that you should always put a comment on each property that clearly describes it, what will a common comment for the three variables be? (// CameraHeight something…). If it actually is a bundled property you should probably put it in Struct.

Google how to create USTRUCT

So if i have a multitude of variables purely for a camera (RTS for context), should I make several structs? One for each category? (height, radius, speeds, etc)?

Also, side question that is a little off-topic. I want to be able to edit the default values of the camera in blueprint, but also have a function in code to reset the variables to their defaults, this way the player can instantly fix their camera if they need to. Is there a way to get their default values or do I just make a separate variable? (One default, one that changes)?

If you don’t need to handle the categories in some specific way, replication/events/etc, you can try and start with one big struct that is your “camera info”. You can get default values from the CDO but I would recomend you to add separate default values that you just copy in a reset function.