# How to make UE4 c++ particle systems?

**URL:** <https://forums.unrealengine.com/t/how-to-make-ue4-c-particle-systems/404751>\
**Category:** FX\
**Tags:** particle-systems, unreal-engine, UE4, question, CPP\
**Created:** [September 16, 2017, 5:48pm UTC](https://forums.unrealengine.com/t/how-to-make-ue4-c-particle-systems/404751 "2017-09-16T17:48:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maximilian758](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/maximilian758/32/777090_2.png) [@maximilian758](https://forums.unrealengine.com/u/maximilian758)\
**Post date:** [September 16, 2017, 5:48pm UTC](https://forums.unrealengine.com/t/how-to-make-ue4-c-particle-systems/404751/1 "2017-09-16T17:48:09Z")

</div>

So i tried to add particle effect to standart projectile from FPS project template and used [this documentation](https://docs.unrealengine.com/latest/INT/Programming/Tutorials/Components/1/index.html) as reference, but it didn’t work. Then i tried to search here and found many answered questions about this, but their solutions didn’t work. For example  
Projectile.h

```
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "SVALKER_2Projectile.generated.h"

UCLASS(config=Game)
class ASVALKER_2Projectile : public AActor
{
	GENERATED_BODY()

	/** Sphere collision component */
	UPROPERTY(VisibleDefaultsOnly, Category=Projectile)
	class USphereComponent* CollisionComp;

	/** Projectile movement component */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = "true"))
	class UProjectileMovementComponent* ProjectileMovement;

public:
	ASVALKER_2Projectile();

	UPROPERTY(VisibleAnywhere)
		class UParticleSystemComponent* PSC;

	/** called when projectile hits something */
	UFUNCTION()
	void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);

	/ **Returns CollisionComp subobject** /
	FORCEINLINE class USphereComponent* GetCollisionComp() const { return CollisionComp; }
	/ **Returns ProjectileMovement subobject** /
	FORCEINLINE class UProjectileMovementComponent* GetProjectileMovement() const { return ProjectileMovement; }
};

```

Projectile.cpp

```
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

#include "SVALKER_2Projectile.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Components/SphereComponent.h"
#include "ConstructorHelpers.h"
#include "ParticleDefinitions.h"

ASVALKER_2Projectile::ASVALKER_2Projectile() 
{
	// Use a sphere as a simple collision representation
	CollisionComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComp"));
	CollisionComp->InitSphereRadius(5.0f);
	CollisionComp->BodyInstance.SetCollisionProfileName("Projectile");
	CollisionComp->OnComponentHit.AddDynamic(this, &ASVALKER_2Projectile::OnHit); // set up a notification for when this component hits something blocking

	// Players can't walk on it
	CollisionComp->SetWalkableSlopeOverride(FWalkableSlopeOverride(WalkableSlope_Unwalkable, 0.f));
	CollisionComp->CanCharacterStepUpOn = ECB_No;

	// Set as root component
	RootComponent = CollisionComp;

	static ConstructorHelpers::FObjectFinder<UParticleSystem> PS(TEXT("ParticleSystem'/Game/StarterContent/Particles/P_Explosion.P_Explosion'"));
	PSC = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("MyPSC"));
	PSC->SetTemplate(PS.Object);

	// Use a ProjectileMovementComponent to govern this projectile's movement
	ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileComp"));
	ProjectileMovement->UpdatedComponent = CollisionComp;
	ProjectileMovement->InitialSpeed = 3000.f;
	ProjectileMovement->MaxSpeed = 3000.f;
	ProjectileMovement->bRotationFollowsVelocity = true;
	ProjectileMovement->bShouldBounce = true;

	// Die after 3 seconds by default
	InitialLifeSpan = 3.0f;
}

void ASVALKER_2Projectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	// Only add impulse and destroy projectile if we hit a physics
	if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL) && OtherComp->IsSimulatingPhysics())
	{
		OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation());
		//Destroy();
	}
}

```

MVS2017 says that “pointer to incomplete type is not allowed”  
at line 27 in Projectile.cpp at PSC variable:

```
PSC->SetTemplate(PS.Object);

```

[this is the answer i referenced](https://answers.unrealengine.com/questions/327192/how-do-i-reference-my-particle-system-in-code.html)

so i tried to find an example of c++ UE4 code to figure out how it works and found [this](http://apprize.info/c/games/12.html) but it didnt work too.  
Can someone point me in the right direction?

---

<div class="post-metadata">

**Author:** ![Raxis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Raxis](https://forums.unrealengine.com/u/Raxis)\
**Post date:** [October 1, 2017, 2:48pm UTC](https://forums.unrealengine.com/t/how-to-make-ue4-c-particle-systems/404751/2 "2017-10-01T14:48:33Z")

</div>

Instead of `#include "ParticleDefinitions.h"` maybe use,

```
#include "Runtime/Engine/Classes/Particles/ParticleSystemComponent.h"

```

instead.
