UE5 根据数据库播放字幕 和 C++碰撞产生爆照特效

一.播放弹幕,使用了数据库来一 一 对应。

之前使用,ScollBox变为horizontal (水平的),但只能做到字幕滑动播放,如下。

后来使用,数据表选择播放代替。首先创建结构体World

以这个结构体,创建数据表DataTable. ALLWORLD

创了个插件,写了个Actor来管理UI

蓝图静态库函数,用来把int 转换为 对应的FName。进而方便实现访问数据表

cpp 复制代码
	UFUNCTION(BlueprintCallable, meta = (DisplayName = "Execute Send RowName", Keywords = "HMSUI sample test testing"), Category = "HMSUITesting")
	static FName HMSUISendRowName(int index);
cpp 复制代码
FName UHMSUIBPLibrary::HMSUISendRowName(int index)
{
	FString TempString = FString::FromInt(index);
	FName ConvertedFString = FName(*TempString);
	return ConvertedFString;
}

创建一个UISystemActor,使用BlueprintImplementableEvent,让蓝图实现切换表里的内容体现在UI上。

cpp 复制代码
UCLASS()
class HMSUI_API AHMSUISystem : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AHMSUISystem();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;
	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = "UI")
	void setIndex(int i);
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MHSUI")
	int index;
};

首先实现BlueprintImplementableEvent函数,使用插件里的蓝图静态库函数转换为FName,再读取表里的结构体。

将这个结构体,传入RunText,加入到视口一段时间后,又消失。

这里如何传入WORLD,使用Expose on Spawn,产生时暴露出来。

这样在C++里也可以,切换UI字幕

二.如何碰撞,产生爆照特效

1.碰撞,这些回调函数。一定要在继承AActor,APawn这样的类上使用,而且一定包含了继承的头文件。我就遇到过我没包含头文件,编译居然没报错。但是你死活用不了里面的碰撞回调函数。后来发现加个头文件,就行了。

只是OverLap的话,还算蛮简单的。头文件,碰撞和回调函数都声明了。

cpp 复制代码
#include "Components/SphereComponent.h"
cpp 复制代码
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "MySceneComponent")
USphereComponent* MySphereCollision;
//碰撞开始的回调函数
UFUNCTION()
void BeginOverlapFunction(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

2.构造函数里写,碰撞大小等

cpp 复制代码
AHMSTarget::AHMSTarget() : AActorBase() {
	MySphereCollision = CreateDefaultSubobject<USphereComponent>(TEXT("MySphereCollision"));
	MySphereCollision->InitSphereRadius(3000.0f);
	RootComponent = MySphereCollision;
}

碰撞后,在回调函数里将 特效生成即可

cpp 复制代码
void AHMSTarget::BeginOverlapFunction(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	UObject* ExplodeNiagara = LoadObject<UObject>(nullptr, TEXT("/Script/Niagara.NiagaraSystem'/Game/Explosions_Niagara/Particles/P_Explosion08.P_Explosion08'"));
	UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, Cast<UNiagaraSystem>(ExplodeNiagara), GetActorLocation(), FRotator::ZeroRotator,FVector(2.f));
}

但要将 NigaraFunctionLibrary的头文件加上,SpawnSystemAtLocation里的参数,也可以不用默认参数。然后就能实现 ,相同类的不同子类 ,碰撞后爆炸的效果。

cpp 复制代码
#include "NiagaraFunctionLibrary.h"
相关推荐
Zhichao_979 小时前
【UE5.3】给vrm角色加上Kawaii Physics
ue5
zhangzhangkeji11 小时前
UE5 材质-37-节点:自定义图元数据(CPD),Custom Primitive Data。
ue5
Zhichao_9712 小时前
【UE5.3】使用Live Link Face给vrm角色添加表情和头部动作
ue5
会思考的猴子17 小时前
UE5 接口 使用
ue5
平行云1 天前
实时云渲染支持在网页上运行UE5开发的3A大作Lyra项目
unity·云原生·ue5·webgl·虚拟现实·实时云渲染·像素流送
AA陈超1 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P07-18.生成火球术
c++·游戏·ue5·游戏引擎·虚幻
曼巴UE52 天前
UE 运行时编辑效果。Gizom使用增强输入改写
c++·ue5
Deveuper2 天前
UE5 暂停蓝图失效方法
ue5
zhangzhangkeji2 天前
UE5 材质-38-节点:GeneratedBand 生成条带 节点
ue5
AA陈超2 天前
LyraStarterGame_5.6 Experience系统加载流程详细实现
c++·笔记·学习·ue5·虚幻引擎·lyra