在公司学习UE4下的C++代码编程时,依照《Unreal Engine4总动员》上的示例编写代码时,总是发生代码六的错误以及一些莫名其妙的错误。下图是书上示例:

这是我敲的代码:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Foat.generated.h"
UCLASS()
class QUICKSTART_API AFoat : public AActor
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage")
int32 TotalDamage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage")
float DamageTimeInSecond;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Transient, Category = "Damage")
float DamagePerSecond;
public:
// Sets default values for this actor's properties
AFoat();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Ti

在使用Unreal Engine 4(UE4)学习C++编程时,遇到代码错误,特别是涉及到UPROPERTY宏与蓝图交互时。发现当UPROPERTY包含BlueprintReadWrite或BlueprintReadOnly等参数时,必须将变量设为public或protected才能避免编译错误。通过调整变量访问权限,成功解决了问题并理解了其背后的原因。
最低0.47元/天 解锁文章
530





