在头文件里定义结构体和结构体变量(注意不要忘了加USTRUCT(BlueprintType)和GENERATED_BODY()!)
USTRUCT(BlueprintType)
struct FHealth
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float health = 100;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float MaxHealth = 100;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
float HealthPercentage = health / MaxHealth;
};
UCLASS()
class EXERCISE_API AYeah : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AYeah();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FHealth Health;
};
蓝图调用: