laser sight

Hello, I need help with the beam particle component. I was following this Bp tutorial:- YouTube i was going to try and convert it to c++. I got it work in BP fine in my project, however, my c++ version doesn’t seem to be working. I believe my lane trace is fine, as the point light at the end of the beam is working, however, there is no beam showing. Again, it does work in my BP version, i must be doing something wrong with the particle component. Any help would be appreciated:


//laser sight
	UPROPERTY(VisibleDefaultsOnly, Category = "Laser")
	class UChildActorComponent* LaserSourceComp;

	UPROPERTY(VisibleDefaultsOnly, Category = "Laser")
	class UPointLightComponent* LaserImpactLight;

	UPROPERTY(EditAnywhere, Category = "Laser")
	class UParticleSystemComponent* LaserBeamPSC;

	UPROPERTY(EditDefaultsOnly, Category = "Laser")
	UParticleSystem* LaserBeamFX;

this is what is in my constructor



        LaserSourceComp = CreateDefaultSubobject<UChildActorComponent>(TEXT("LightSource"));
	LaserSourceComp->AttachTo(GetMesh());
	
	LaserImpactLight = CreateDefaultSubobject<UPointLightComponent>(TEXT("LaserImpact"));
	LaserImpactLight->Intensity = 20.0f;
	LaserImpactLight->AttenuationRadius = 20.f;
	LaserImpactLight->LightColor = FColor(1.0, 0.0, 0.0);
	LaserImpactLight->AttachTo(LaserSourceComp);

	LaserBeamPSC = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("LaserBeam"));
	LaserBeamPSC->SetActive(true);
	LaserBeamPSC->Template = LaserBeamFX;
	LaserBeamPSC->AttachTo(RootComponent);

this is my tick event


void ACharacter::Tick(float DeltaTime) 
{

	Super::Tick(DeltaTime);

	

	const FVector TraceStart = LaserSourceComp->GetComponentLocation();
	
	const FVector TraceEnd = TraceStart + (LaserSourceComp->GetForwardVector() * 5000);


	FCollisionQueryParams TraceParams(TEXT("Trace"), true, this);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.AddIgnoredActor(this);

	TraceParams.bTraceComplex = false;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);
	
	FVector_NetQuantize LaserTargetLocation;
	
	if (Hit.bBlockingHit)
	{
		LaserTargetLocation = Hit.Location;
	}
	else
	{
		LaserTargetLocation = TraceEnd;
	}

	//this works
	//DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, false, 1.0f);

	if (LaserBeamFX)
	{
		if (LaserBeamPSC)
		{
			//LaserBeamPSC->Template = LaserBeamFX;
			LaserBeamPSC->Activate();
			LaserBeamPSC->SetBeamSourcePoint(0, TraceStart, 0);
		        LaserBeamPSC->SetBeamTargetPoint(0, LaserTargetLocation, 0);
	
		}
		
	}

	if (LaserImpactLight)
	{
		FVector lvNewLocation = LaserTargetLocation - LaserImpactLight->GetForwardVector();
		LaserImpactLight->SetWorldLocation(lvNewLocation);
	}



}

Where you’ve used ‘LaserBeamPSC->Activate()’ - Try using ‘SetActive(true, true)’ instead, I’ve usually had more luck with that one!

Also, it’s possible that unless the beams locations are close to the actual emitter itself, they might be being culled by it’s bounds. To get around that (temporarily) you could just massively increase the bounds in the particle system itself and ensure that ‘Use Fixed Bounds’ is checked

You sir, are the man. That did it, thanks!!