[UE4]反射


1、根據名字獲得類(C++支持,藍圖本身不支持但可以通過工廠模式模擬)

  國外大神提供的封裝好的C++實現:

https://github.com/getsetgames/BlueprintReflection

功能:

1) Get Class By Name(根據類的名字獲得類)

The Get Class By Name blueprint function can be used to retrieve a Class (UClass) object by providing its name.

2) Construct Object From Class(根據類來構建對象)

The Construct Object From Class blueprint function can be used to create an instance of any class that derives from Object (UObject).

3)Construct Object From Class Name(根據類的名字來生成對象)

The Construct Object From Class Name blueprint function can be used to create an instance of any class that derives from Object (UObject) by providing the name of the class. This effectively runs GetClassByName and ConstructObjectFromClass in one call.

 

2、根據名字調用函數(藍圖支持)

一、Set Timer by Function Name

二、Set Timer by Event

3、根據名字獲得成員變量(C++支持)

4、根據名字獲得組件(藍圖支持)

函數“Get Components by Class”有一個Bug,這個藍圖一經拖放出來的“Component Class”就是“ActorComponent”,這時直接編譯是會出錯的,要重新選擇一下其他的“Component Class”然后再選擇“Actorcomponent”(也可以直接手動選擇一下“Actorcomponent”),再次編譯就能通過了。

 

運行時按“Z”,就會把場景中所有屬於“ActorComponent”的組件名字打印出來。

 在藍圖函數庫(同一個項目中任何藍圖都可以使用的函數)中添加一個自定義方法:GetComponentByName(根據名字來獲得組件)

 4、根據名字獲得類(藍圖中使用工廠模式模擬實現,這是偽實現)

首先在藍圖函數庫中添加一個輔助函數:GetClassName(獲得類實例對象的顯示名字。類實例對象:場景中已經生成的實例對象)

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM