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"
相关推荐
1204157137 肖哥11 小时前
UE5 MRQ渲染:解决采样不够造成的角色残影问题
ue5·音视频
zhangzhangkeji15 小时前
UE5 C++(6-2):描述角色 EndPlay 原因的枚举类 EEndPlayReason::Type,此命名空间里定义了一个枚举类。
ue5
陈友松18 小时前
记录下UE5.3源码在系统升级windows11后使用VS2022出现的编译错误,以及下载慢提速的方法
ue5
zhangzhangkeji20 小时前
UE5 C++(5):虚幻C++游戏架构,创建C++默认类,以及如何自定义游戏模式
ue5
每天回答3个问题1 天前
Lua 函数教程
开发语言·ue5·ue4·lua
AI视觉网奇1 天前
ue 条件判断
笔记·算法·ue5
Zhichao_971 天前
【UE5.3 C++】ARPG游戏 03-创建Character
游戏·ue5
AI视觉网奇2 天前
Plugin ‘vits_native‘ failed to load because module ‘vits_native‘
笔记·ue5
gshh__2 天前
SuperMap Hi-Fi 3D SDK for Unreal 如何实现横断面分析
3d·ue5·游戏引擎·supermap
AI视觉网奇2 天前
ue ‘vits_native’ 插件加载失败 ue ‘xxx’ 插件加载失败
c++·笔记·ue5