Download

Can't set velocity after un-parenting actor

I’m working on a game where the player shoots itself towards objects, and it should ledge on them, so that when these objects move, the player will move with it. To get this result, I’m making the player a child of the object it collides with via the following blueprint:

This seems to work just fine. After that, when the player shoots itself somewhere else, it should detach from the object and move again, but when I try to do that (both in C++ and blueprints), the velocity is a zero length vector and the player just freezes at the spot it clicked. I detached the player in C++ with the following code:


this->DetachRootComponentFromParent( true );

And with the blueprint called “Detach Actor from Actor”.

The velocity gets set with the AddImpulse function as follows:


collider->AddImpulse( SpawnRotation.Vector() * movementSpeed, NAME_None, true );

For both cases in the hierarchy it looks like the player has indeed no parent anymore.
Also the player’s mobility is still “moveable” (I also check this in C++ to be sure, and it prints it’s true).
The “Simulate Physics” option is still set to true (or maybe I’m looking wrong…).

I don’t know why the player is not moving after it had a parent. Thanks for the help in advance.

After days of trying I finally figured out the problem (porting it to a 4.7 project made me able to look into all the components and their settings). Apparently when you attach your root scene-component to another actor, unreal automatically copies the physic settings of that object the component that got attached to it. To get rid of this behaviour I am now casting the object to the only object that moves in the scene, and since this one simulates physics it keeps its settings. Also to make sure the physics are on when I apply the impulse, I set the Simulate Physics option to true for the root component (which is the collider I apply the force on as well).


collider->SetSimulatePhysics( true );