函数参数说明(在GameplayStatics.h中)
将一个粒子放到指定位置上播放:
/** Plays the specified effect at the given location and rotation, fire and forget. The system will go away when the effect is complete. Does not replicate. * @param WorldContextObject - Object that we can obtain a world context from * @param EmitterTemplate - particle system to create * @param Location - location to place the effect in world space * @param Rotation - rotation to place the effect in world space * @param bAutoDestroy - Whether the component will automatically be destroyed when the particle system completes playing or whether it can be reactivated */ UFUNCTION(BlueprintCallable, Category="Effects|Components|ParticleSystem", meta=(Keywords = "particle system", WorldContext="WorldContextObject", UnsafeDuringActorConstruction = "true")) static UParticleSystemComponent* SpawnEmitterAtLocation(UObject* WorldContextObject, class UParticleSystem* EmitterTemplate, FVector Location, FRotator Rotation = FRotator::ZeroRotator, bool bAutoDestroy = true);
另一种重载形式:
static UParticleSystemComponent* SpawnEmitterAtLocation(UWorld* World, class UParticleSystem* EmitterTemplate, const FTransform& SpawnTransform, bool bAutoDestroy = true);
将一个粒子attach到某个Component上播放:
/** Plays the specified effect attached to and following the specified component. The system will go away when the effect is complete. Does not replicate. * @param EmitterTemplate - particle system to create * @param AttachComponent - Component to attach to. * @param AttachPointName - Optional named point within the AttachComponent to spawn the emitter at * @param Location - Depending on the value of Location Type this is either a relative offset from the attach component/point or an absolute world position that will be translated to a relative offset * @param Rotation - Depending on the value of LocationType this is either a relative offset from the attach component/point or an absolute world rotation that will be translated to a realative offset * @param LocationType - Specifies whether Location is a relative offset or an absolute world position * @param bAutoDestroy - Whether the component will automatically be destroyed when the particle system completes playing or whether it can be reactivated */ UFUNCTION(BlueprintCallable, Category="Effects|Components|ParticleSystem", meta=(Keywords = "particle system", UnsafeDuringActorConstruction = "true")) static UParticleSystemComponent* SpawnEmitterAttached(class UParticleSystem* EmitterTemplate, class USceneComponent* AttachToComponent, FName AttachPointName = NAME_None, FVector Location = FVector(ForceInit), FRotator Rotation = FRotator::ZeroRotator, EAttachLocation::Type LocationType = EAttachLocation::KeepRelativeOffset, bool bAutoDestroy = true);
具体使用实例
头文件,其中MuzzleFX在蓝图中设置为具体哪个粒子资源,Mesh是要AttachTo的Component
UPROPERTY(EditDefaultsOnly) UParticleSystem* MuzzleFX; /** weapon mesh: 3rd person view */ UPROPERTY(VisibleDefaultsOnly, Category = Mesh) USkeletalMeshComponent* Mesh;
cpp中调用:
//此方法只播放一遍即结束 UGameplayStatics::SpawnEmitterAttached(MuzzleFX, Mesh, "MyAttachPoint");
=====================================================
上面粒子是用蓝图直接创建ParticleSystem(粒子系统),下面是用C++代码创建ParticleSystem:
头文件中定义:
UParticleSystem* TestParticle; UParticleSystemComponent* LastPSC;
创建ParticleSystem:
void AHGameMode::LoadParticlesClass() { static ConstructorHelpers::FObjectFinder<UParticleSystem> MyParticleSystem(TEXT("ParticleSystem'/Game/Particles/Oneshot/P_mc01CIrcle05_large_oneshot.P_mc01CIrcle05_large_oneshot'")); if (MyParticleSystem.Succeeded()) { TestParticle = MyParticleSystem.Object; } }
播放粒子:
void AHGameMode::PlayParticle_01() { LastPSC = UGameplayStatics::SpawnEmitterAttached(TestParticle, MyCharacter->GetMesh(), "MyParticle"); }
如果是循环播放的粒子,手动控制粒子的播放和关闭(如果是一个只播放一次的粒子,可以不用手动停止):
//ActivateSystem的bool参数表示开启特效后是否重置特效(从头播放) LastPSC->ActivateSystem(true);
关闭特效:
LastPSC->DeactivateSystem();
如果希望 DeactivateSystem 之后,再次开启 ActivateSystem 的时候能自动激活特效,需要禁用自动销毁:
UParticleSystemComponent->bAutoDestroy = false;
参考:
How can I get a particle to spawn in a specific location?
https://answers.unrealengine.com/questions/36451/particle-spawns-in-incorrect-location.html
How can I spawn an instance of an emitter during runtime?
相关推荐
UE4 C++ 离线API 下载直接使用 无障碍
UE4 C++教程 虚幻四C++教程
这是ue4 4.22.1 engine 版本的例子。实现了通过蓝图把场景中的AStaticMeshActor和两个动态材质实例UMaterialInstanceDynamic 传给c++ 自定义函数参数。 并在自定义函数里面实现两张材质的动态交替变更,其中一张材质...
毕业设计基于C++的一款UE4射击游戏源码。一款UE4射击游戏Demo,包含UE4游戏框架及整套联网射击游戏功能。一款UE4射击游戏Demo,包含UE4游戏框架及整套联网射击游戏功能。一款UE4射击游戏Demo,包含UE4游戏框架及整套...
UE4 socket 数据接收以及发送,功能示例
UE4学习笔记----使用C++之控制球体运动并使用移动粒子效果(源代码)
虚幻4粒子特效教程
亲测可用,内涵UE4的插件设置,从此敲C++代码的速度就起飞了
UE4 C++JSON读取示例.zip
UE4vs代码段,包括快捷创建碰撞事件的三种函数,快捷创建三种枚举,快捷创建结构体,快捷创建控制台输出的7个代码段。
UE4_UE5播放视频带声音
直接拷贝到UE4资源文件夹可用,里面包含瀑布和水雾。模型声音材质贴图粒子都有。淘宝上买比较贵,直接惠及大家了。原作者在油管上有教程,B站上也有,可搜索借鉴。
该文档包含了UE4 C++ API的所有类、函数、宏、枚举等内容,并提供了详细的说明和示例代码。 文档内容 UE4 C++离线API文档的内容主要分为以下几部分: 类(Classes):该部分包含了UE4 C++ API中所有类的信息,包括...
①:得到线段我们的线段集合S(本次项目鼠标点击得到线段(p1,p2两点)已经在ue4蓝图里面实现,这一步就不过多阐述) ②:移除孤立的线段(两端的点都是孤立的); ③:拆分所有的线段(就是将所有的相交线线段拆...
1. 继承C++类的蓝图类直接调用 2.C++类中的全局函数,任意蓝图都能调用的方式。
将一个多边形的所有点(点数组)按顺序输入,顺逆皆可,将其拆分成多个不重叠的三角形,输出所有三角形的点的index;
1.默认关卡中,在函数中填写本地exe程序的绝对路径 2.打开工程前,重新生成VS文件
UE4 Render Target 的使用具体的蓝图应用方法。 从数学原理上讲解 在一个mesh 上画图案的方法
包括UE4中C++的各种常用知识点,为初学ue4游戏编程的同学提升c++编程能力提供一定的帮助!
一个简单实现点击按钮更换图片的UE4C++代码例子,例子很简洁,使用到了简单的UI创建、类型转换等等相关常用的UE4中需要的方法