[UE4]C++中SpawnActor用法(动态创建Actor)
来源:互联网 发布:电池优化 编辑:程序博客网 时间:2024/06/10 12:54
注:这里创建actor跟unity有明显不同
ue不能创建一个单独的actor,单独的actor也没意义,ue里的actor是用来继承的
这里创建的actor都是实例化actor的子类,细想下,并不影响动态创建对象。
ue417用下面的写法貌似直接挂了,看SpawnActor的具体参数来写最新参数
http://aigo.iteye.com/blog/2270177
C++中创建一个Level并添加的Runtime当中
- Level.Add(GetWorld()->SpawnActor<ABuildingModLevel>());
C++中Spawn一个基于蓝图的Actor
https://answers.unrealengine.com/questions/60897/spawn-actorobject-from-code.htm
Here is how I spawn a blueprint via C++. Note that the blueprint I spawn has a base class that was created in C++ also.
.h
- TSubclassOf<YourClass> BlueprintVar; // YourClass is the base class that your blueprint uses
.cpp(注意,这段代码必须放在构造函数中。UE4其他类型的蓝图,比如Widget蓝图,都可以通过下面这种方式加载。)
- ClassThatWillSpawnTheBlueprint::ClassThatWillSpawnTheBlueprint(const class FPostConstructInitializeProperties& PCIP)
- : Super(PCIP)
- {
- static ConstructorHelpers::FObjectFinder<UBlueprint> PutNameHere(TEXT("Blueprint'/Path/To/Your/Blueprint/BP.BP'"));
- if (PutNameHere.Object)
- {
- BlueprintVar = (UClass*)PutNameHere.Object->GeneratedClass;
- }
- }
PutNameHere
is just an arbitrary name you give to the constructor helper. The path to your blueprint is found by finding your blueprint in the content browser, right clicking it, and choosing Copy Reference
. Then, just paste that in between the quotes.
Now, you're ready to spawn the blueprint. You can do it in BeginPlay() or wherever, just not in the constructor.(这段代码必须放在非构造函数中,比如BeginPlay()中)
- UWorld* const World = GetWorld(); // get a reference to the world
- if (World)
- {
- // if world exists
- YourClass* YC = World->SpawnActor<YourClass>(BlueprintVar, SpawnLocation, SpawnRotation);
- }
If you don't know your SpawnLocation or SpawnRotation you can just throw in FVector(0,0,0) and FRotator(0,0,0) instead.
So, since your blueprint base class was also created in C++ this makes it easy to interact with your blueprint from code. It's as simple as YC->SomeVariable = SomeValue
. Hope that helps.
- [UE4]C++中SpawnActor用法(动态创建Actor)
- UE4 动态创建Actor并且附加static mesh
- ue4 SpawnActor和SpawnAIFromClass
- ue4 动态增删查改 actor,bp
- UE4入门 1 如何在空项目中创建Actor并显示在游戏中 C++
- 在UE4的蓝图中创建一个自动销毁的Actor
- UE4 Runtime下动态给Actor添加组件
- UE4 自动创建破碎物件的actor(C++版本)
- UE4中动态创建并加载流关卡
- UE4中动态时钟蓝图
- UE4 VR项目中actor永远面向头显的蓝图
- 在C++Builder中动态创建控件
- UE4在C++中动态加载资源
- UE4中创建vive控制器交互
- UE4蓝图节点翻译---Get Parent Actor
- UE4蓝图节点翻译---Is Child Actor
- UE4蓝图节点目录翻译【目录】--- Actor
- UE4中Lambda的一些用法
- h5开发相关积累
- Base64转为图片,并保存到本地以及数据库
- Android GLSurfaceView
- html之快捷键
- centOS 7 安装 CUPS 打印服务器,安装映美 FP-730K打印机共享
- [UE4]C++中SpawnActor用法(动态创建Actor)
- MySQL可视化工具
- LeetCode-Add to List 494. Target Sum
- 内部类
- 虚拟机Linux IP地址更改
- Qt 5.5 操作 Excel 的速度 效率问题
- 《深入理解java虚拟机 》学习笔记01——运行时数据区域
- python写的Android的 tcpdump 数据实时发送到wireshark
- Java 泛型