C++ Equivalent to "Set Velocity" node in Floating Pawn Movement [SOLVED]

So, I cannot find the function/variable that works like the “Set Velocity” node in Blueprint. This node was extremely useful to completely change my floating pawns velocity on the fly without using any movement inputs. Is there an equivalent function that I am completely missing? I’ve scrawled through the source code going all the way from the floating pawn source code to Aactor, and I can’t find anything like that dang node. It seems so simple, but I just can’t find what I need to do.

This node: Set Velocity posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

You have a couple of options, but perhaps the best is UPrimitiveComponent::SetAllPhysicsLinearVelocity. With that, you should just need your actor’s root component, which is the component you’ll call this function on. For example:

FVector NewVelocity;   // whatever you want your actor's new velocity to be
AActor* MyActor;
[...]   // some code to get a pointer to the actor whose velocity you want to change
if (MyActor != nullptr)
{
    USceneComponent* Component = MyActor->GetRootComponent();
    if (Component != nullptr)
    {
        Component->SetAllPhysicsLinearVelocity(NewVelocity, false);
    }
}

If you want to see all of your options for manipulating physics velocities for an actor in C++, check out the API page for UPrimitiveComponent.

I’ll try this when I get home from work! Thank you!

This unfortunately didn’t work. My root component is a USphereComponent, and is not meant to be simulating physics. I need something that works in a kinematic space, not the physics space. I should be able to figure something out! Even if I have to pass a variable off into Blueprint in order to use that node, it should work. Not optimal, but if I have to resort to it I will!

How about a different answer?

I just now got a chance to see your blueprint graph preview, and was reminded that (duh) you’re dealing with a UFloatingPawnMovement component.

In that case, how about just setting the velocity directly on the movement component? Like so:

FVector NewVelocity;   // whatever you want your actor's new velocity to be
AActor* MyActor;
[...]   // some code to get a pointer to the actor whose velocity you want to change
if (MyActor != nullptr)
{
    UMovementComponent* MovementComponent = Cast<UMovementComponent>(MyActor->GetComponentByClass(UFloatingPawnMovement::StaticClass()));
    if (MovementComponent != nullptr)
    {
        MovementComponent->Velocity = NewVelocity;
    }
}

Hopefully this does the trick!

This functions perfectly! Visual Studio throws a typical “member is inaccessible” error/highlight which is annoying, but it compiles fine and works perfectly. You also taught me a valuable concept in casting/pointing to a parent class for specific things as well. Thank you!