Below is an example header file of using UPROPERTY on a private member variable.
This header file seems to work, but I did run into a one-time bug where this particular component stopped saving changes to anything in the details window (the blueprint compile button wouldn’t change to “needs to be compiled” regardless of any setting changed on this component). Deleting the component and re-adding it fixed the problem and changes could be made again, but I wasn’t able to reproduce the bug after that. Since I couldn’t reproduce the bug, I couldn’t deduce if using UPROPERTY on the private member was the cause or not.
So I’m wondering: Is it safe to use UPROPERTY on a private member or do they have to be protected instead?
#pragma once
#include "CoreMinimal.h"
#include "Components/StaticMeshComponent.h"
#include "TankBarrel.generated.h"
UCLASS(meta = (BlueprintSpawnableComponent))
class BATTLETANK_API UTankBarrel : public UStaticMeshComponent
{
GENERATED_BODY()
public:
void Elevate(float relativeSpeed);
private:
UPROPERTY(EditAnywhere, Category = Setup)
float MaxDegreesPerSecond = 20;
UPROPERTY(EditAnywhere, Category = Setup)
float MaxElevationDegrees = 40;
UPROPERTY(EditAnywhere, Category = Setup)
float MinElevationDegrees = 0;
};