i want my projectile to go active again after disactivate but it wont work
can you be a bit more specific?
what do you currently have? (maybe a screen shot of the blueprint in question)
what do you mean by “disactivate”? did it hit a wall, did its lifespan expire?
are you trying to place it back at the “Start Point” to trigger it again?
are you talking about something completely different?
i have a box colosoin on the projectile if it hit a player after 0.5 second it will set active un checked update the projectile velocity to go back and hit the player agian but it seems when i set active checked again it wont work
i just used a print string on the velocity update and it seems that it update the 0,0,0 the second time i think thats why it wont move
you might need to call the SetUpdateComponent()
for the movement component (in this case the ProjectileMovement
Component of the projectile after the collision.
you might be able to accomplish it by sending “Reset = true” to the Activate()
node
otherwise you may need to pull out ProjectileMovement->SetUpdateComponent()
part of the projectile motion Component deactivates that specifically so that a projectile doesn’t just keep moving after it hit something.
ok i got the
*ProjectileMovement->SetUpdateComponent()
- where should i plug it or what should i do with it
i duplicated the projectile movement and after disabling the first one it will start using the duplicated one and it works , i think thats enough for me i dont need it to keep doing it twice is enough
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.
That worked for us. In bp we disabled the auto register update component, then call Set Update Component with the root component when the projectile gets activated. This got it to work consistently on each activation.