C++ 类基础:.h/.cpp 文件分工与 UFUNCTION(BlueprintCallable)¶
理解 UE C++ 类中头文件和源文件的分工,并写一个能被蓝图调用的方法。
文件分工¶
- 创建类之前记得勾选公开 Public 选项。
.h文件 = 声明方法。.cpp文件 = 编写方法如何运行。
在 类名称.h 文件内¶
public:
// Sets default values for this actor's properties
类名称();
UFUNCTION(BlueprintCallable, Category = "分类名称")
int 方法名(int a, int b);
在 类名称.cpp 文件内¶
// Called when the game starts or when spawned
void A类名称::BeginPlay()
{
Super::BeginPlay();
}
int A类名称::方法名(int a, int b) {
int c = a + b;
return c;
}
注意事项¶
- 每次修改 C++ 内容之后,记得在项目(编辑器)界面右下角 Compile 编译代码。
ID:83 | 更新:2026-06-11