// Fill out your copyright notice in the Description page of Project Settings. #include "FXComponent.h" #include "NiagaraSystem.h" #include "NiagaraComponent.h" #include "NiagaraFunctionLibrary.h" #include "NiagaraDataChannel.h" #include "NiagaraDataChannelHandler.h" #include "NiagaraDataChannel_Islands.h" #include "NameRegisterLibrary.h" #include "NiagaraDataChannelAccessor.h" // Sets default values for this component's properties UFXComponent::UFXComponent() { // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features // off to improve performance if you don't need them. PrimaryComponentTick.bCanEverTick = true; // ... } // Called when the game starts void UFXComponent::BeginPlay() { Super::BeginPlay(); // ... } // Called every frame void UFXComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); // ... } UObject* UFXComponent::PlayFX(UObject* FXAsset, USceneComponent* MeshComp, FName SocketName, FVector LocalOffset, FRotator LocalRotation, int32 DataChannelCount, FFXSpawnInfo SpawnInfo) { UObject* FXObject = nullptr; if (UNiagaraSystem* NiagaraAsset = Cast(FXAsset)) { FXObject = SpawnSystemAttached(NiagaraAsset, MeshComp, SocketName, LocalOffset, LocalRotation, SpawnInfo); }else if (UNiagaraDataChannelAsset* NDCAsset = Cast(FXAsset)) { FNiagaraDataChannelSearchParameters SearchParams = (GetOwner()->GetActorLocation()); FXObject = UNiagaraDataChannelLibrary::WriteToNiagaraDataChannel(this, NDCAsset, SearchParams, DataChannelCount, true, true, true, *GetOwner()->GetName()); if (auto NDCWriter = Cast(FXObject)) { NDCWriter->WritePosition(UNameRegisterLibrary::Name_Position, 0, LocalOffset); NDCWriter->WriteVector(UNameRegisterLibrary::Name_Rotation, 0, FVector(LocalRotation.Pitch, LocalRotation.Yaw, LocalRotation.Roll)); NDCWriter->WriteQuat(UNameRegisterLibrary::Name_Quaternion, 0, LocalRotation.Quaternion()); } } return FXObject; } UNiagaraComponent* UFXComponent::SpawnSystemAttached(UNiagaraSystem* SystemTemplate, USceneComponent* AttachToComponent, FName AttachPointName, FVector Location, FRotator Rotation, FFXSpawnInfo SpawnInfo) { UNiagaraComponent* FXObject = UNiagaraFunctionLibrary::SpawnSystemAttached(SystemTemplate, AttachToComponent, AttachPointName, Location, Rotation, SpawnInfo.LocationType, SpawnInfo.bAutoDestroy, SpawnInfo.bAutoActivate, SpawnInfo.PoolingMethod, SpawnInfo.bPreCullCheck); if (FXObject) { FXObject->SetTickBehavior(SpawnInfo.TickBehavior); } return FXObject; }