? 欧美在线看一区二区三区,日本高清视频一区二区三区免费,韩国三级BD高清在线观看
聯(lián)系我們

給我們留言

聯(lián)系我們

地址:福建省晉江市青陽(yáng)街道洪山路國(guó)際工業(yè)設(shè)計(jì)園納金網(wǎng)

郵箱:info@narkii.com

電話:0595-82682267

(周一到周五, 周六周日休息)

當(dāng)前位置:主頁(yè) > 3D教程 > 圖文教程

UE4 C++實(shí)現(xiàn)動(dòng)態(tài)加載的問(wèn)題

來(lái)源: 52vr | 責(zé)任編輯:傳說(shuō)的落葉 | 發(fā)布時(shí)間: 2019-06-04 08:32 | 瀏覽量:

[UE4]C++實(shí)現(xiàn)動(dòng)態(tài)加載的問(wèn)題

 

動(dòng)態(tài)加載UObject和動(dòng)態(tài)加載UClass分別用LoadObject(),和LoadClass() ,兩者均在在UObjectGlobals.h中。

 

另外注意:LoadClass的模版名稱,不能直接寫(xiě)UBlueprint,例如:LoadClass是錯(cuò)誤的,創(chuàng)建藍(lán)圖時(shí)選擇的是什么父類,則寫(xiě)對(duì)應(yīng)的父類名,假如是Actor,那么要寫(xiě)成:LoadClass>,否則無(wú)法加載成功。

路徑名也必須帶_C后綴(LoadObject不需要帶_C后綴),例如,藍(lán)圖路徑是:Blueprint'/Game/Blueprints/MyBP.MyBP',

加后綴以后,則是:Blueprint'/Game/Blueprints/MyBP.MyBP_C',

例子:

 

 
  1. UClass* Test = LoadClass(NULL, TEXT("Blueprint'/Game/Blueprints/MapPathBrush_BP.MapPathBrush_BP_C'"));  
 

 

官方還沒(méi)出文檔,只能先看代碼注釋:
 

 
  1. // Load an object.  
  2. templateclass T >   
  3. inline T* LoadObject( UObject* Outer, const TCHAR* Name, const TCHAR* Filename=nullptr, uint32 LoadFlags=LOAD_None, UPackageMap* Sandbox=nullptr )  
  4. {  
  5.     return (T*)StaticLoadObject( T::StaticClass(), Outer, Name, Filename, LoadFlags, Sandbox );  
  6. }  

 

 
  1. // Load a class object.  
  2. templateclass T >   
  3. inline UClass* LoadClass( UObject* Outer, const TCHAR* Name, const TCHAR* Filename=nullptr, uint32 LoadFlags=LOAD_None, UPackageMap* Sandbox=nullptr )  
  4. {  
  5.     return StaticLoadClass( T::StaticClass(), Outer, Name, Filename, LoadFlags, Sandbox );  
  6. }  

 

 
  1. /** 
  2.  * Find or load an object by string name with optional outer and filename specifications. 
  3.  * These are optional because the InName can contain all of the necessary information. 
  4.  * 
  5.  * @param ObjectClass   The class (or a superclass) of the object to be loaded. 
  6.  * @param InOuter       An optional object to narrow where to find/load the object from 
  7.  * @param InName        String name of the object. If it's not fully qualified, InOuter and/or Filename will be needed 
  8.  * @param Filename      An optional file to load from (or find in the file's package object) 
  9.  * @param LoadFlags     Flags controlling how to handle loading from disk 
  10.  * @param Sandbox       A list of packages to restrict the search for the object 
  11.  * @param bAllowObjectReconciliation    Whether to allow the object to be found via FindObject in the case of seek free loading 
  12.  * 
  13.  * @return The object that was loaded or found. NULL for a failure. 
  14.  */  
  15. COREUOBJECT_API UObject* StaticLoadObject( UClass* Class, UObject* InOuter, const TCHAR* Name, const TCHAR* Filename = NULL, uint32 LoadFlags = LOAD_None, UPackageMap* Sandbox = NULL, bool bAllowObjectReconciliation = true );  
  16. COREUOBJECT_API UClass* StaticLoadClass(UClass* BaseClass, UObject* InOuter, const TCHAR* Name, const TCHAR* Filename = NULL, uint32 LoadFlags = LOAD_None, UPackageMap* Sandbox = NULL);  

 

 

 LoadObject加載例子,不需要添加后綴:

 
  1. UTexture2D* Tex = LoadObject(NULL, TEXT("Texture2D'/Game/Textures/UI/tex_test001.tex_test001'"));  

 
 

可以用LoadObject加載的文件包括:

Texture、Material、SoundWave、SoundCue、ParticlesSystem、AnimMontage、BlendSpace(1D,2D,3D)、AnimSequence、AnimBlueprint、SkeletalMesh等等。這些文件的父類都是UObject,所以也可以先加載為UObject*然后再?gòu)?qiáng)轉(zhuǎn)為具體的類型,例如:

 
  1. UObject* Obj = LoadObject(NULL, TEXT("SkeletalMesh'/Game/MyMesh.MyMesh'"));  
  2. USkeletalMesh* MyMesh = Cast(Obj);  

 

  

另外有兩個(gè)全局函數(shù)叫:StaticLoadObject()和StaticLoadClass(),應(yīng)該是LoadObject()和LoadClass()的早期版本,前者需要手動(dòng)強(qiáng)轉(zhuǎn),后者使用模版封裝過(guò),使用更方便,推薦使用后者



相關(guān)文章
網(wǎng)友評(píng)論

您需要登錄后才可以發(fā)帖 登錄 | 立即注冊(cè)

關(guān)閉

全部評(píng)論:0條

推薦
熱門(mén)