我正在开发一款游戏,我正在尝试创建一个函数。在尝试重建它时,出现错误“无法找到头文件名称为“FActorSpawnParameters”的“结构”。 *.cpp没有错误
#pragma once
#include "CoreMinimal.h"
#include "Gameplay/Items/PBItem_Base.h"
#include "GameplayTagContainer.h"
#include "Utility/PBMathLib.h"
#include "Engine/World.h"
#include "PBChildWeaponComponent.h"
#include "PBWeapon_Base.generated.h"
...
UFUNCTION(Server, reliable)
void FireProjectileRPC(TSubclassOf<class APBProjectile> ProClass, FVector MLocation, FRotator MRotation, FActorSpawnParameters SParams, UWorld* MWorld);
#include "Gameplay/Items/PBWeapon_Base.h"
#include "Gameplay/Items/PBProjectile.h"
#include "Engine/SkeletalMeshSocket.h"
#include "Gameplay/Soldier/PBInventoryInterfaceLib.h"
#include "Gameplay/Soldier/PBSoldierInterfaceLib.h"
...
void FireProjectileRPC_Implementation(TSubclassOf<APBProjectile> ProClass, FVector MLocation, FRotator MRotation, FActorSpawnParameters SParams, UWorld* MWorld) {
...
}
添加了不同的标头并包含但头文件中仍然存在相同的构建错误
您实际上不应该通过 RPC 提供其中几个参数,请记住这是通过网络发送的数据,您希望它尽可能轻量。
话虽如此,您收到错误的原因是因为如果我没记错的话,FActorSpawnParameters 不是
USTRUCT
,这意味着您不能在标记为 UFUNCTION
的函数中使用它,这是因为UBT(Unreal Build Tool)无法为其生成反射代码。
考虑到上述内容,我建议您重新考虑
FireProjectileRPC_Implementation
函数的实现,FVector MLocation
和 FRotator MRotation
是“可接受的”(尽管如果这是在武器演员类中,您可以在演员本身内的网格或组件来确定这些)。
在没有更多实施细节的情况下,我建议您考虑一些基本建议。
uint8
继承 UENUM
和 GetProjectileClass
助手
函数来确定您需要生成的类(因为这将
总共 255 节课,消耗也大大减少
带宽)。GetWorld()
是一个函数
这通常在所有主要的虚幻类中都可用(绝对是
AActor
)。FActorSpawnParameters
的实现中构造您的 FireProjectilRPC
(假设这是从武器类生成一个项目,在武器 actor 中使用 GetOwner()
将返回武器的所有者,只要它设置正确,它将是你的“性格”)。如果您可以提供更多信息和代码,我很乐意提出一些额外的建议。