[UE4]反射

时间秒杀一切 提交于 2021-02-16 22:11:05

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(获得类实例对象的显示名字。类实例对象:场景中已经生成的实例对象)

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!