SpawnEmitterAttached not working

My particle system won’t spawn after calling the spawn emitter function.

// Battery Collector - Nire

#include "BatteryCollector.h"
#include "BatteryPickup.h"

// Set default values
ABatteryPickup::ABatteryPickup()
{
	GetMesh()->SetSimulatePhysics(true);
}

void ABatteryPickup::BeginPlay()
{
	BatteryPower = FMath::FRandRange(100.f, 300.f);
}

void ABatteryPickup::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	
	if (CollectionParticles)
	{
		UpdateBeamTargetPoint();
	}

}

void ABatteryPickup::UpdateBeamTargetPoint()
{
	FVector Socket = UGameplayStatics::GetPlayerCharacter(this, 0)->GetMesh()->GetSocketLocation("spine_02");
	ParticleSystem->SetBeamTargetPoint(0, Socket, 0);
}

void ABatteryPickup::OnDestroy()
{
	Destroy();
}

void ABatteryPickup::WasCollected_Implementation()
{
	// Use the base pickup behaviour
	Super::WasCollected_Implementation();
	
	// Setting up particle system arc
	ParticleSystem = UGameplayStatics::SpawnEmitterAttached(CollectionParticles, GetMesh());
	ParticleSystem->bVisible = true;
	GetWorldTimerManager().SetTimer(ParticleTimer, this, &ABatteryPickup::OnDestroy, 1.f, false);
}

float ABatteryPickup::GetPower()
{
	return BatteryPower;
}

Hey NarutoAM,

Can you answer the following?

  • Is ParticleSystem being created in a parent class? This is done with CreateDefaultSubobject
  • How are you calling, WasCollected( )?
  • Has CollectionParticles been set so the SpawnEmitterAttached has a valid template to spawn from?

Thanks.

WasCollected( ) is being called everytime a player is in range and has pressed “C” beside an object of this class.

CollectionParticles’ target is set to user set and its source is emitter, I’m not sure if that answers your question( Sorry, I’m new ).

ParticleSystem should be created when WasCollected( ) is called, and its only being being created in this class. Sorry if my answers weren’t clear.

I am not seeing any issue on my end using UGameplayStatics::SpawnEmitterAttached( ).

I would suggest going through the tutorial again and make sure that you are following the instructions.

Ok, I’ll try to redo the tutorial excactly and I’ll return back here. Thanks for the replies :slight_smile:

Whoops, I should’ve probably gave you my header file, it turned out I put UPROPERTY instead of UFUNCTION.