Resetting projectile for object pool

Hey,
I am using an object pool to store and use projectile when needed. Teleporting them to the weapon location and activating the projectile movement component when the weapon is fired then teleporting them back to the pool when they impact in the world. This is so we don’t have to keep spawning and destroying projectiles at run time.

However, I have found that if the projectile collides with something in the world I cannot add velocity to it a second time once it has been pulled from the pool. It does not seem to be the act of resetting that causes this as returning to the object to the pool after a delay rather than on collision allows it to be re-fired with no issues. Any ideas why this is and how to fix it would be appreciated.
J

1 Like

Have you found a solution for this?

I managed to work around it but I’m not sure my method is ideal.

I destroy the Projectile Component when adding the projectile to the pool.

I spawn a Projectile Component when teleporting the projectile out of the pool.

I feel like “spawning a component” use less resources than “spawn actor” but I’m not comfortable with it anyway.

I managed to work around it but I’m not sure my method is ideal.

I destroy the Projectile Component when adding the projectile to the pool.

I spawn a Projectile Component when teleporting the projectile out of the pool.

I feel like “spawning a component” use less resources than “spawn actor” but I’m not comfortable with it anyway.

Digging through the code, I found the following function:

void UProjectileMovementComponent::StopSimulating(const FHitResult& HitResult)
{
	SetUpdatedComponent(NULL);
	Velocity = FVector::ZeroVector;
	OnProjectileStop.Broadcast(HitResult);
}

So all you have to do to restart a ProjectileMovementComponent should be to reset the UpdatedComponent and Velocity. It’s probably a good idea to call

ProjectileMovementComponent->Activate();

as well, which also calls

SetComponentTickEnabled(true);
2 Likes

I believe setActiveComponent is cleared on hit, have you tried reactivating it with setActiveComponent to reset the projectile?

I think you need to call

SetUpdatedComponent(GetRootComponent());

in order to make the projectile got update correctly again

I think you need to call

SetUpdatedComponent(GetRootComponent());

in order to make the projectile got update correctly again

2 Likes

This is the correct answer - thank you!

1 Like