在头文件里定义结构体和结构体变量(注意不要忘了加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;
};
蓝图调用:



本文介绍了在UE4游戏引擎开发中,如何在C++中定义结构体UStruct,并使其能在蓝图中被调用。通过添加USTRUCT(BlueprintType)和GENERATED_BODY()宏,可以确保结构体在蓝图系统中的兼容性。
最低0.47元/天 解锁文章
5791

被折叠的 条评论
为什么被折叠?



