-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySpawnActorParticle.cpp
More file actions
38 lines (29 loc) · 1.03 KB
/
Copy pathMySpawnActorParticle.cpp
File metadata and controls
38 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "MySpawnActorParticle.h"
#include "NiagaraComponent.h"
// Sets default values
AMySpawnActorParticle::AMySpawnActorParticle()
{
PrimaryActorTick.bCanEverTick = false;
MyRoot = CreateDefaultSubobject<USceneComponent>(TEXT("MyRoot"));
#if WITH_EDITORONLY_DATA
MyRoot->bVisualizeComponent = true;
#endif
RootComponent = MyRoot;
MyNiagaraComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("MyNiagaraComponent"));
MyNiagaraComponent->SetupAttachment(RootComponent);
ParticleColor = FVector(1.f, 0.f, 0.f);
}
// Called when the game starts or when spawned
void AMySpawnActorParticle::BeginPlay()
{
Super::BeginPlay();
if (MyMaterialInterface != nullptr)
{
UMaterialInstanceDynamic* MyDynamicMaterialInstance = UMaterialInstanceDynamic::Create(MyMaterialInterface, MyNiagaraComponent);
if (MyDynamicMaterialInstance != nullptr)
{
MyDynamicMaterialInstance->SetVectorParameterValue(FName("Base Color"), ParticleColor);
MyNiagaraComponent->SetVariableMaterial(FName("MyMaterial"), MyDynamicMaterialInstance);
}
}
}