UE5中C++对蓝图类的软引用方法

静态方法:

对资源的软引用:

FSoftObjectPath MeshSoftRef("StaticMesh'/Game/StarterContent/Props/SM_Door.SM_Door'");
 

对类的软引用:

FSoftClassPath bpwidgetcalss(TEXT("Blueprint'/Game/bp_widget.bp_widget_C'"));
实例:
FSoftClassPath bpwidgetcalss(TEXT("Blueprint'/Game/bp_widget.bp_widget_C'"));
UClass* widgetclass = bpwidgetcalss.TryLoadClass();
bpwidget = widgetclass;

使用ConstructorHelpers::FClassFinder的方法可以找到特定的蓝图类

ConstructorHelpers::FClassFinder MyCat(TEXT("Blueprint'/Game/bp/bp_Cat.bp_Cat_C'"));
TSubclassOf ChildType;
ChildType = MyCat.Class;
 

使用LoadClass函数可以加载一个蓝图类

UClass* StaticMeshClass = LoadClass(nullptr, TEXT("Blueprint'/Game/Test/BP_StaticMesh.BP_StaticMesh_C'"));
 

动态引用的方法:

LoadObject的函数可以加载一个资源

UStaticMesh* StaticMesh = LoadObject(nullptr, TEXT("StaticMesh'/Game/StarterContent/Props/SM_Door.SM_Door'"));
 

LoadClass的函数可以加载一个蓝图类

UClass* TestClass = LoadClass(nullptr, TEXT("Blueprint'/Game/Test/BP_Test.BP_Test_C'"));

动态的软引用方法:

FSoftObjectPath可以动态软引用一个资源

FSoftObjectPath MeshSoftRef("StaticMesh'/Game/StarterContent/Props/SM_Door.SM_Door'");

FSoftClassPath可以动态软引用一个蓝图类

FSoftClassPath ClassSoftRef("Blueprint'/Game/Blueprint/BP_Test.BP_Test_C'");
 

TSoftObjectPtr可以对任何UObject的子类进行软引用

TSoftObjectPtr TextureSoftRef = TSoftObjectPtr(FSoftObjectPath("Texture2D'/Game/Textures/MyTexture.MyTexture'"));
 

动态创建组件的方法:

UStaticMeshComponent* SMC = NewObject(this);
SMC->SetStaticMesh(SM);
SMC->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
SMC->RegisterComponent();
 

你可能感兴趣的:(ue5,前端,javascript)