UE4 学习笔记1 变量的初始化

1 在头文件声明变量

 

  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage")
    int32 TotalDamage;
    
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage")
    float DamageTimeInSeconds;
    
    UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Transient, Category = "Damage")
    float DamagePerSecond;

 UPROPERTY() 宏命令 定义变量的属性  

EditAnywhere   在UI编辑器中可编辑   

BlueprintReadWrite  在蓝图中可读写

Category = "Damage" 在编辑器中以组“Damage”显示

2 变量初始化两种方式

AMyActor::AMyActor() : TotalDamage(200),
DamageTimeInSeconds(1.f)
{

}

 

AMyActor::AMyActor()
{
  ChangeValue();
}
AMyActor::ChangeValue() 
{

TotalDamage = 200;
    DamageTimeInSeconds = 1.f;
}
 

3 此时如果在编辑器中修改变量

TotalDamage
DamageTimeInSeconds

值,DamagePerSecond的值并不会随之改变 

需要添加edit回调

#if WITH_EDITOR
void AMyActor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
  
changeValue();
  super::PostEditChangeProperty(PropertyChangedEvent);
} #endif

 4 c++ wizard 中方法如果想要在Blueprint 中显示,在方法声明前添加宏

UFUNCTION(BlueprintCallable, Category="Damage")
void CalculateValues();

5 c++ 调用Blueprint方法(未测试)

UFUNCTION(BlueprintImplementableEvent, Category="Damage")
void CalledFromCpp();

6 Blueprint可override方法(未测试)

UFUNCTION(BlueprintNativeEvent, Category="Damage")
void CalledFromCpp();

This version still generates the thunking method to call into the Blueprint VM. So how do you provide the default implementation? The tools also generate a new function declaration that looks like _Implementation(). You must provide this version of the function or your project will fail to link. Here is the implementation code for the declaration above.

void AMyActor::CalledFromCpp_Implementation()
{
    // Do something cool here
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值