UE4 常用的宏

UCLASS

  • Blueprintable 可创建蓝图
  • BlueprintType 可作为蓝图变量
  • NotBlueprintType 不可作为蓝图变量

UPROPERTY

  • EditAnywhere 蓝图类和实例可编辑
    • EditDefaultsOnly 蓝图类可编辑
    • EditInstanceOnly 实例可编辑
  • BlueprintReadWrite 蓝图类可读可写get/set
    • BlueprintReadOnly 蓝图类可读get
    • BlueprintWriteOnly 蓝图类可写set

UFUNCTION
BlueprintImplementableEvent:由蓝图实现。

UFUNCTION(BlueprintImplementableEvent)
void Jump();

在这里插入图片描述

BlueprintNativeEvent:c++实现默认功能,蓝图重写后调用蓝图的功能。

UFUNCTION(BlueprintNativeEvent)
void OnOverlap(AActor* OverlappedActor, AActor* OtherActor);
//绑定
OnActorBeginOverlap.AddDynamic(this, &ABaseCoin::OnOverlap);
void ABaseCoin::OnOverlap_Implementation(AActor* OverlappedActor, AActor* OtherActor) {
	if (Cast<ABasePlayer>(OtherActor) != nullptr)
	{
		Destroy();
	}
}

在这里插入图片描述

BlueprintCallable:可供蓝图调用的函数

UFUNCTION(BlueprintCallable)
void PlayCustomDeath();

在这里插入图片描述

创建和销毁UCLASS

UUserProfile* newobject = NewObject<UUserProfile>(GetTransientPackage(), UUserProfile::StaticClass());
if (newobject)
{ 
	newobject->ConditionalBeginDestroy();
	newobject = nullptr; 
}

强制内存回收
GetWorld()->ForceGarbageCollection( true );

创建结构体

USTRUCT()
struct xxx_API FColoredTexture
{
	GENERATED_USTRUCT_BODY()
public:
  UPROPERTY( EditAnywhere, BlueprintReadWrite, Category = HUD )
  UTexture* Texture;
  UPROPERTY( EditAnywhere, BlueprintReadWrite, Category = HUD )    
  FLinearColor Color;
};

创建枚举

UENUM()
enum Status
{
  Stopped UMETA(DisplayName = "Stopped"),
  Moving UMETA(DisplayName = "Moving"),
  Attacking UMETA(DisplayName = "Attacking"),
};
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值