使用虚幻引擎5.1.1和Visual Studio Community 2022 17.2.6。尝试将C函数公开给UE蓝图。在头文件中的函数上方添加UFUNCTION
宏时,C无法在VS中编译,并出现编译错误:
在需要标识符时找到“类型结束”
在函数行,第25行。
代码:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Components/StaticMeshComponent.h"
#include "MazeGenerator.generated.h"
UCLASS()
class MINOTAUR_API UMazeGenerator : public UActorComponent
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
int mX;
UPROPERTY(EditAnywhere)
int mY;
// Sets default values for this component's properties
UMazeGenerator();
UFUNCTION(BlueprintCallable)
void LoadVoxels(std::string);
private:
UStaticMesh** maze_voxels;
};
我在这里和youtube上寻找答案,没有找到任何与我的问题完全匹配的东西,大多是关于结尾处有一个错误的分号的东西,当然,人们在不同的上下文中成功地做到了这一点。这可能不会涉及UE编辑器本身,因为它实际上是一个Visual Studio编译错误。
1条答案
按热度按时间wvyml7n51#
BlueprintCallable
函数只能有一些特定的参数类型和返回类型:UObjects
或UStructs
标记为Blueprintable
(包括几乎所有常用的对象类型,例如AActor
继承类型、actor组件、纹理/材质/基本上是您可以在内容浏览器中找到的任何其他内容)、bool
s、float
/int32
/int64
中的数字、FString
/FText
/FName
中的文本、数组/集合/Map上面提到的类型,以及一些委托。除此之外,不能使用其他类型,因为Blueprint系统不知道如何在图形中为这样的类型制作/显示引脚。例如:
std::string
或任何其他C++标准库类型也是如此。如果不需要跨越Blueprint世界,您可以自由使用标准库类型。但是,如果您想在任何Unreal特定代码中使用字符串,最好使用
FString
。您可以轻松地将std::string
转换为FString
,请参阅this Unreal论坛帖子。