How to spawn a particle system

I am trying to spawn an emitter using the explosion effect given in the starter content folder of UE4. I am trying to use static ConstructorHelpers::FObjectFinder<UParticleSystem> explosion(TEXT("/Game/FirstPerson/Particles/P_Explosion.P_Explosion"));

but it gives me the error

G:\UE_4.24\Engine\Source\Runtime\CoreUObject\Public\UObject/ConstructorHelpers.h(110) : error C2664: ‘void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)’: cannot convert argument 1 from ‘T *’ to ‘UObject *’

I have tried a lot of different solutions and have researched for hours on end trying to solve this, but I haven’t been able to and so I’d really appreciate it if someone could help me out.

Projectile.h

#pragma once

#include "CoreMinimal.h"
#include "ParticleDefinitions.h"
#include "GameFramework/Actor.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
#include "Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h"
#include "FirstShooterProjectile.generated.h"


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

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

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

public:
	AFirstShooterProjectile();
	/** 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; }
	void FireInDirection(const FVector& ShootDirection, float rocketCharge);
	UPROPERTY(EditAnywhere)
	UParticleSystem* explosiveSpawn;

	
};

Projectile.cpp

#include "FirstShooterProjectile.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Components/SphereComponent.h"
#include "UObject/ConstructorHelpers.h"
#include "Engine/World.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
#include "Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStaticsTypes.h"



AFirstShooterProjectile::AFirstShooterProjectile()
{
	
	// 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, &AFirstShooterProjectile::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;

	// Use a ProjectileMovementComponent to govern this projectile's movement
	ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileComp"));
	ProjectileMovement->UpdatedComponent = CollisionComp;
	ProjectileMovement->bRotationFollowsVelocity = true;
	ProjectileMovement->bShouldBounce = false;
	ProjectileMovement->ProjectileGravityScale = 0;

	// Die after 10 seconds by default
	InitialLifeSpan = 10.0f;
	static ConstructorHelpers::FObjectFinder<UParticleSystem> explosion(TEXT("/Game/FirstPerson/Particles/P_Explosion.P_Explosion"));
	explosiveSpawn = explosion.Object;
	
}

void AFirstShooterProjectile::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 != this) && (OtherComp != NULL))
	{	
		//Get World
		UWorld* world = GetWorld();
		FActorSpawnParameters SpawnParams;
		FRotator rotator = Hit.ImpactNormal.Rotation();
		FVector spawnLocation = Hit.ImpactPoint;
		UGameplayStatics::SpawnEmitterAtLocation(world, explosiveSpawn, spawnLocation, rotator, true);










		 
		Destroy();
	}
}

void AFirstShooterProjectile::FireInDirection(const FVector& ShootDirection, float rocketCharge)
{
	ProjectileMovement->Velocity = ShootDirection * (rocketCharge * 10000.0f);
}

I provided the entirety of the files involved in case that helps. This is my first post, so sorry if I'm missing any common practices or formalities.

Make a Uproperty (EditAnyWhere) for your effect and make a bp out of your projectile then spawn that bp when weapon fires.

In the header:

UPROPERTY(EditAnywhere)
class UParticleSystem* explosiveSpawn;

In the cpp file:

#include "Particles/ParticleSystem.h"
1 Like

And don’t forget to always protect your pointers.

Thank you so much!! I had tried doing this one simple thing for so many hours and I can’t believe I just needed these small changes!! I could cry, you’re a solid lad, thanks so much!

The other answer worked out for me, but thanks so much! I appreciate it!