I have a bug with my gun projectile that i am not able to fix, my projectile stays stationary and it spawn 10cm from the gun muzzle socket

I am trying to develop a system for firing projectile from my plasma pistol but after doing all the necessary work i am stuck on this bug where my projectile spawn 10 cm from my gun’s muzzle socket and the projectile remain stationary in the air, how can i fix that

projectile.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Components/SphereComponent.h"
#include "NiagaraComponent.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraSystem.h"
#include "PlasmaProjectile.generated.h"

UCLASS()
class MYSIDESCROLLER_API APlasmaProjectile : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	APlasmaProjectile();

	UPROPERTY(VisibleAnywhere)
	USphereComponent* CollisionComponent;

	UPROPERTY(VisibleAnywhere)
	UProjectileMovementComponent* ProjectileMovement;

	UPROPERTY(VisibleAnywhere)
	UNiagaraComponent* PlasmaBall;

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effects")
	class UNiagaraSystem* ExplosionEffect;

	UFUNCTION()
	void OnHit(UPrimitiveComponent* HitComp,AActor* OtherActor,UPrimitiveComponent* OtherComp,FVector NormalImpulse,const FHitResult& Hit);

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

};

projectile.cpp
// Fill out your copyright notice in the Description page of Project Settings.


#include "PlasmaProjectile.h"

// Sets default values
APlasmaProjectile::APlasmaProjectile()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	CollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
	CollisionComponent->InitSphereRadius(15.0f);
	RootComponent = CollisionComponent;

	PlasmaBall = CreateDefaultSubobject<UNiagaraComponent>(TEXT("PlasmaBall"));
	PlasmaBall->SetupAttachment(RootComponent);

	ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileComponent"));
	ProjectileMovement->UpdatedComponent = CollisionComponent;
	ProjectileMovement->InitialSpeed = 4000.f; 
	ProjectileMovement->MaxSpeed = 4000.f;
	ProjectileMovement->bRotationFollowsVelocity = true;
	ProjectileMovement->ProjectileGravityScale = 0.0f; 


}

// Called when the game starts or when spawned
void APlasmaProjectile::BeginPlay()
{
	Super::BeginPlay();
	
	if (CollisionComponent) {
		CollisionComponent->OnComponentHit.AddDynamic(this, &APlasmaProjectile::OnHit);
	}
}

// Called every frame
void APlasmaProjectile::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	
	DrawDebugSphere(GetWorld(), GetActorLocation(), 10.f, 8, FColor::Red, false, 1.0f);
	FVector CurrentLoc = GetActorLocation();

	UE_LOG(LogTemp, Warning, TEXT("next location: %s"), *CurrentLoc.ToString());
}

void APlasmaProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	if (OtherActor && (OtherActor != this) && OtherComp)
	{
		// 1. Spawn explosion at the EXACT spot we touched
		UNiagaraFunctionLibrary::SpawnSystemAtLocation(GetWorld(), ExplosionEffect, Hit.ImpactPoint, Hit.ImpactNormal.Rotation());

		// 2. Destroy the projectile
		Destroy();
	}
}

character.cpp

void ASpaceCatCharacter::fire()
{
	if (PlasmaProjectileClass)
	{

		FVector MuzzleLocation = PlasmaPistol->GetSocketLocation(TEXT("Muzzle"));
		FRotator MuzzleRotation = PlasmaPistol->GetSocketRotation(TEXT("Muzzle"));

		FActorSpawnParameters SpawnParams;
		SpawnParams.Owner = this;
		SpawnParams.Instigator = GetInstigator();

		GetWorld()->SpawnActor<APlasmaProjectile>(PlasmaProjectileClass, MuzzleLocation, MuzzleRotation, SpawnParams);
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("PlasmaProjectileClass is NOT set in the Character Blueprint!"));
	}
}

My guess is its something in the Niagara component you are using. Your on tick debug that draws a sphere at the actor location is showing that the projectile actor is moving based upon the first picture. How do you have the UNiagaraComponent* PlasmaBall; setup?

You can test it by adding a temp static mesh to the projectile. if it moves normally then you can narrow it down to a niagara issue. You may not have local space enabled in the emitter is the lowest hanging fruit.

yeah i just found out it was the nigagra component, i replaced it with a mech and i am planning to add a plasma trail nigagra effect attached to the mech.

Cool, a static mesh is going to be easier to work with for your situation. If you needed the niagara particle to update is position with the component it was spawned from you need local space = true in the emitter properties here.

do you know how to make the projectile spawn at the muzzle not 10 cm from it

I would check the sockets on the mesh. That is how you are getting the spawn location. Open the static mesh asset and make sure the socket with the name “Muzzle“ is located where you want the projectile to spawn.