Actor location being overwritten

Mr.Pathetic
Wed, 10 Jul 2019 17:28:13 +0000
World Creation

I have the following code:

void AWeaponBase::OnThrow()
{
	if (CurrentOwner)
	{
		const ACharacter* ThrowingOwner = CurrentOwner;
		DetachFromCurrentOwner();

		const APlayerCameraManager* CameraManager = UGameplayStatics::GetPlayerCameraManager(GetWorld(), 0);

		const FVector StartThrowLocation = CameraManager->GetCameraLocation() + FRotationMatrix(CameraManager->GetCameraRotation()).GetScaledAxis(EAxis::X) * 100.0f;

		SetActorLocation(StartThrowLocation, false, nullptr, ETeleportType::ResetPhysics);
	}
}

When I run it, the weapon actor should be teleported in front of the player, but it just drops to the ground.

I realized that the reason for this is not that the weapon is not being moved, but rather that it’s being returned to the original position in the next frame. However, I can’t figure out where it’s being moved back. I don’t know if it has something to do with physics simulation or what’s happening. Can somebody help?

5 posts - 1 participant