[UE5] GetSocketLocation returning origin or local position instead of world position

/// <summary>
/// Shoot weapon
/// </summary>
bool ABaseWeapon::Fire(FVector AimDirection)
{
	//get bullet from bullet pool
	ABaseBullet* bullet = GetBulletFromPool();
	if (bullet == nullptr)
	{
		//error no bullets
		return false;
	}

	bullet->SetBulletInfo(m_BulletInfo);

	//give it a vector and rotate only the X  so that it only moves on the YZ plane
	FVector spawnLocation = GetActorLocation();
	FRotator spawnRotation;
	FTransform spawnTransform = FTransform();

	if (m_MeshRef != nullptr && m_MeshRef->DoesSocketExist("BulletSocket"))
	{
		spawnTransform = m_MeshRef->GetSocketTransform("BulletSocket", RTS_World);
		//spawnLocation = m_MeshRef->GetSocketLocation("BulletSocket");
		if(spawnTransform.IsValid())
			spawnLocation = spawnTransform.GetLocation();
	}
		
	spawnRotation =  AimDirection.Rotation();

	//tell gameinstance to place a bullet at socket location
	bullet->FireBullet(spawnLocation, spawnRotation);

	return true;
}

which is called by player

void APlayerCharacter::Fire()
{
	if (!CanFire)//player may be in fire animation
		return;

	CanFire = false;//player is firing
	GetAimFrame();//get firing angle

	//shoot bullet from weapon
	m_SpawnedWeapon->Fire(AimVector());

	//animate player firing
}

which is called on fire input

PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &APlayerCharacter::Fire);
1 Like