Projectile movement cant go active again after disactivate

Just giving a short update on this as I am digging into this problem for my projectile object pooling. It seems like setting the projectile component bAutoActivate = false; and than calling SetUpdatedComponent() along with Activate() on the projectile movement component later does not trigger it to start moving again. I was able to isolate this problem and get it to start moving after being disabled by manually toggling bAutoActivate inside PIE during gametime. I will be trying to track down the cause of this problem and will update this post once I discover a solution.

-UPDATE- only 5 minutes later
Well that didn’t take long. Setting bAutoActivate = true; on the ProjectileMovementComp got it to begin movement again… very weird. I will dig deeper and find out why. Brb.

UPDATE
Found the little guy stopping Activate() from working.

bAutoUpdateTickRegistration = true; is the default. THIS will stop Activate() from working completely with ProjectileMovementComponents… (from what I can see during testing)

bAutoUpdateTickRegistration = false; will now let you Activate() and Deactivate() as you please.

I’ll be looking more into why this is occurring but on the surface its hard to tell. There are only a few functions where this is relevant… Ill update this again If I find the exact reason.

UPDATE
Okay after furthering testing it appears like you also need to override this in ProjectileMovementComponent
virtual void StopSimulating(const FHitResult& HitResult);
and prevent it from callling SetUpdatedComponent(NULL);

void USpellProjectileMovementComponent::StopSimulating(const FHitResult& HitResult)
{
	Velocity = FVector::ZeroVector;
	ClearPendingForce(true);
	UpdateComponentVelocity();
	OnProjectileStop.Broadcast(HitResult);
}

this is my overridden version of the function.
I also did an override for Activate() as well so I can set its velocity back to its initial speed.

void USpellProjectileMovementComponent::Activate(bool bReset)
{
	if (bReset || ShouldActivate() == true)
	{
		SetComponentTickEnabled(true);
		SetActiveFlag(true);
		UpdateSpellVelocity(); // <- this is a custom function to sets its velocity back to its initialspeed.

		OnComponentActivated.Broadcast(this, bReset);
	}
}

Below is the UpdateSpellVelocity() function. This is just essentially what is called during InitializeComponent() but with some of the “filler” removed.

void USpellProjectileMovementComponent::UpdateSpellVelocity()
{
	// InitialSpeed > 0 overrides initial velocity magnitude.
	if (InitialSpeed > 0.f)
	{
		// Defaulted to just using 1.0 FVector so it resets to our BaseValue every time.
		Velocity = FVector(1.0, 0, 0) * InitialSpeed;
	}

	if (bInitialVelocityInLocalSpace)
	{
		SetVelocityInLocalSpace(Velocity);
	}

	if (bRotationFollowsVelocity)
	{
		if (UpdatedComponent)
		{
			FRotator DesiredRotation = Velocity.Rotation();
			if (bRotationRemainsVertical)
			{
				DesiredRotation.Pitch = 0.0f;
				DesiredRotation.Yaw = FRotator::NormalizeAxis(DesiredRotation.Yaw);
				DesiredRotation.Roll = 0.0f;
			}

			UpdatedComponent->SetWorldRotation(DesiredRotation);
		}
	}

	UpdateComponentVelocity();

	if (UpdatedPrimitive && UpdatedPrimitive->IsSimulatingPhysics())
	{
		UpdatedPrimitive->SetPhysicsLinearVelocity(Velocity);
	}
}

Will update again if I find out anymore info.

4 Likes