UE5 获取基元组件 GUID 代码示例
在 UE5 中,可以使用以下代码获取基元组件的 Guid:
#include "Components/PrimitiveComponent.h"
// 获取基元组件的 Guid
FGuid GetPrimitiveComponentGuid(UPrimitiveComponent* PrimitiveComponent)
{
if (PrimitiveComponent)
{
return PrimitiveComponent->ComponentId.GetGuid();
}
return FGuid();
}
使用示例:
#include "MyActor.h"
AMyActor::AMyActor()
{
UPrimitiveComponent* PrimitiveComponent = CreateDefaultSubobject<UPrimitiveComponent>(TEXT("PrimitiveComponent"));
// 获取基元组件的 Guid
FGuid Guid = GetPrimitiveComponentGuid(PrimitiveComponent);
}
请确保已包含 'Components/PrimitiveComponent.h' 头文件,并且代码位于实际的类或函数中。
原文地址: http://www.cveoy.top/t/topic/pjfj 著作权归作者所有。请勿转载和采集!