13{
14 UNiagaraComponent* NiagaraComponent = nullptr;
15
16 if (IsValid(Template) == false || IsValid(MeshComp) == false)
17 {
18 return nullptr;
19 }
20
21 if (Template->IsLooping())
22 {
23 return nullptr;
24 }
25
26
27 if (Attached)
28 {
29 NiagaraComponent = UNiagaraFunctionLibrary::SpawnSystemAttached(
30 Template,
31 MeshComp,
32 SocketName,
33 LocationOffset,
34 RotationOffset,
35 EAttachLocation::KeepRelativeOffset,
36 true,
37 false,
38 ENCPoolMethod::AutoRelease
39 );
40 }
41 else
42 {
43 const FTransform MeshTransform = MeshComp->GetSocketTransform(SocketName);
44
45 NiagaraComponent = UNiagaraFunctionLibrary::SpawnSystemAtLocation(
46 MeshComp->GetWorld(),
47 Template,
48 MeshTransform.TransformPosition(LocationOffset),
49 (MeshTransform.GetRotation() * RotationOffsetQuat).Rotator(),
50 FVector(1.0f),
51 true,
52 false,
53 ENCPoolMethod::AutoRelease
54 );
55 }
56
57 if (IsValid(NiagaraComponent) == false)
58 {
59 return nullptr;
60 }
61
62 NiagaraComponent->SetUsingAbsoluteScale(bAbsoluteScale);
63 NiagaraComponent->SetRelativeScale3D_Direct(Scale);
65 NiagaraComponent->Activate(true);
66
67 return NiagaraComponent;
68}