게임 엔진/Unreal
[Unreal] 프로퍼티 관련 예제
AlgorFati
2020. 10. 8. 12:16
언리얼 구조체를 Property로 사용하는 방법
USTRUCT(Blueprintable)
struct FTestStructData
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere)
float x;
UPROPERTY(EditAnywhere)
float y;
UPROPERTY(EditAnywhere)
float z;
UPROPERTY(EditAnywhere)
float quatX;
UPROPERTY(EditAnywhere)
float quatY;
UPROPERTY(EditAnywhere)
float quatZ;
UPROPERTY(EditAnywhere)
float quatW;
};
class PHYSICSANIMATION_API TestCharacter : public ACharacter
{
//...
public:
UPROPERTY(EditAnywhere, Category = "My")
TArray<FTestStructData> DataList;
//...
}
Property를 이용하여 Client Command를 만드는 방법
class PHYSICSANIMATION_API TestCharacter : public ACharacter
{
//...
public:
UFUNCTION(Exec)
void TestRandomHitCommand();
//...
}
에디터 인스턴스 창에는 Property 값 설정이 표시되지 않도록 하면서, 블루프린트 창에서는 값 설정이 표시되도록 하는 방법 (인스턴스 창에서 Property 값 설정이 표시되면, 편집 속도가 엄청 느려질 수 있다.)
다음 코드에서 프로퍼티 GridCell과 GridPlatform은 인스턴스 디테일 창에서는 표시되지 않도록 하여 에디터가 느려지지 않도록 하고, 블루프린트 창에서는 표시되도록 하여 값을 편집할 수 있도록 하기 위해, EditDefaultsOnly 프로퍼티 타입을 이용한다.
//..
UCLASS()
class AGridGenerator : public AActor, public IGridLink
{
//..
UPROPERTY(EditDefaultsOnly, Category = "Components")
UInstancedStaticMeshComponent* GridCell;
UPROPERTY(EditDefaultsOnly, Category = "Components")
UStaticMeshComponent* GridPlatform;
//..
};
인스턴스 디테일 창에는 GridCell과 GridPlatform이 더이상 표시되지 않는다.
블루프린트 창에서는 GridCell과 GridPlatform의 디테일 값을 편집할 수 있다.
시행착오
1. BlueprintReadOnly로 설정된 property 변수는 반드시 public 한정자를 사용하여야 한다.
그렇지 않은 경우 다음과 같은 에러가 난다.
MSB3075 : 이 명령을 실행할 권한이 있는지 확인하세요.
public:
UPROPERTY(BlueprintReadonly)
int32 TempVal;
2. Custom c++ UObject를 blueprint로 상속받고 싶은 경우
UCLASS(Blueprintable)을 명시해주어야 blueprint 상속 가능한 base class list에 표시된다.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "GameCore/CustomStructs.h"
#include "ItemBase.generated.h"
/**
*
*/
UCLASS(Blueprintable)
class UItemBase : public UObject
{
GENERATED_BODY()
public:
virtual void UseItem(AActor* InActor) {}
const FItem& GetItem() const { return Item; }
protected:
UPROPERTY()
FItem Item;
};