UnrealEngine:加载

静态加载

ConstructorHelpers::FClassFinder() FObjectFinder()

在构造函数中完成加载,无法改变路径

 

UTexture2D* texture;

static ConstructorHelpers::FObjectFinder<UTexture2D> Texture(TEXT("/Game/StarterContent/Textures/T_Spark_Core"));

if (Texture.Successed())

{

  texture = Texture.Object;

}

 

 

动态加载

LoadObject()  StaticLoadObject()

LoadObject()用来加载非蓝图资源,如贴图

LoadClass()用来加载蓝图并获取蓝图类

UMaterial* mt = LoadObject<UMaterial>(nullptr, TEXT("/Game/Map/Materials/grass.grass"));

UMaterial* mt = Cast<UMaterial>(StaticLoadObject(UMaterial::StaticClass(), nullotrm, TEXT("/Game/Map/Materials/grass.grass")))

 

 

加载纹理

#include "CoreMinimal.h"

#include "Kismet/BlueprintFunctionLibrary.h"

#include "Engine/Texture2D.h"

#incldue "LoadFile.generated.h"

#include "AssetRegistryModule.h"
#include "FileHelpers.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "AssetToolsModule.h"
#include "UObject/SavePackage.h"
#include "Factories/MaterialInstanceConstantFactoryNew.h"

 

UCLASS()

class TWODTEST_API ULoadFile : public UBlueprintFunctionLibrary

{

  GENERATED_BODY()

  

  UFUNCTION(BlueprintCallable, meta = (DisplayName = "LoadTextureFromPath", keywords = "Load"), Category = "LoadFile")

  UTexture2D* LoadTextureFromPath(const FString& Path)

  {

    if (Path.isEmpty())  return NULL;

    return Cast<UTexture2D>(StaticLoadObject(UTexture2D::StaticClass(), NULL, *(Path)));

  }

}

 

 

 

posted @   言午丶  阅读(37)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示