淘先锋技术网

首页 1 2 3 4 5 6 7

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"),
};