AddImpulse gets Queued up and executed with next AddImpulse

Hi,
I am experiencing something very strange right now. I try to spawn a projectile from a gun, and always accelerate it to the speed of the gun + a delta (muzzle veloctiy).

	//SPAWN PROJECTILE
	const FVector location = ProjectileSpawn->GetComponentLocation();
	const FRotator rotation = ProjectileSpawn->GetComponentRotation();
	AActor* projectile = GetWorld()->SpawnActor(Ammunition->Projectile, &location, &rotation);

	//GET ROOTS
	UPrimitiveComponent* projectileRoot = Cast<UPrimitiveComponent>(projectile->GetRootComponent());
	UPrimitiveComponent* gunRoot = Cast<UPrimitiveComponent>(GetAttachmentRoot());

	//CALCULATE THE IMPULSE THAT RESULTS IN THE BULLET HAVING THE SAME SPEED AS THE GUN + A DELTA (muzzleVelocity)
	const FVector gunVelocity = gunRoot->GetPhysicsLinearVelocityAtPoint(GetComponentLocation());
	const FVector muzzleVelocity = rotation.Vector() * Ammunition->MuzzleSpeed;
	const float projectileMass = projectileRoot->CalculateMass();
	const FVector impulse = gunVelocity * projectileMass + muzzleVelocity * projectileMass;

	//APPLY THAT IMPULSE
	projectileRoot->AddImpulse(impulse);

	//DEBUG
	GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Red,
		TEXT("gunVelocity: ") + gunVelocity.ToString() +
		TEXT("\nmuzzleVelocity: ") + muzzleVelocity.ToString() +
		TEXT("\nimpulse gun part: ") + (gunVelocity * projectileMass).ToString() +
		TEXT("\nimpulse muzzle part: ") + (muzzleVelocity * projectileMass).ToString() +
		TEXT("\nimpulse: ") + impulse.ToString());

	//APPLY RECOIL
	gunRoot->AddImpulseAtLocation(100 * -impulse * Ammunition->recoilFactor, location);

The impulse does not get applied on the projectile. The recoil does get applied on the gun.

It gets even stranger: If add an AddImpulse in the tick function of my projectile blueprint, then this impulse gets applied AND the impulse of my c++ function also gets applied. But only at the same time as the tick function applies the impulse. If I apply the impulse in blueprint only after 30 frames, then both impulses will be delay by 30 frames. It seems like my first impulse gets somehow queued up, and executed with the next one? Please help!

Hey pulp_user,

When are you applying that impulse, as in what function are you applying the impulse in? Are you sure that that function is ever getting called?

I’d like if you could create a simplified version of this repro in a test project so I could take a closer look at your setup.

Hello,

I am marking this topic as resolved for tracking purposes, as we have not heard from you in a few days. If this issue persists, feel free to respond to this thread. For any new issues, please create a new Answerhub topic.

Have a great day