Wrong location after spawning

hi. used this function to spawn and attach my weapon to an arrow.

  void AHeroCharacter::SpawnGun()
    	if (WhatToSpawn)
    		UWorld* const World = GetWorld();
    		if (World)
    			FActorSpawnParameters sp;
    			sp.Owner = this;
    			sp.Instigator = Instigator;
    			FVector SpawnLocation =GunTemp->GetComponentLocation() ;
    			FRotator SpawnRotation = GunTemp->GetComponentRotation();
    			AWeapon* Weapon=World->SpawnActor<AWeapon>(WhatToSpawn, SpawnLocation, SpawnRotation, sp);

and i called this function in begin play but it appears far away from arrow component after spawning, how to fix it?

For SpawnLocation and SpawnRotation pass zeros. These are relative offsets, not world positions. Alternatively, you can do:

Weapon->AttachRootComponentTo(GunTemp, NAME_None, EAttachLocation::KeepWorldPosition);