SetActorLocation Does Not Update Vehicle Position

I am trying to simulate aircraft movement in my vehicle class and update aircraft’s position via SetActorLocation function. Though it returns true and vehicle location changes programmatically, I verify with GetActorLocation, vehicle position is not updated visually at all and I am sure that this was working in 4.8. What changed between two versions so that it is not working anymore?

Edit: I tried it with default c++ vehicle template by calling SetActorLocation under Tick function and the case is the same.

Hello eozgonul,

I have a few questions for you that will help narrow down what issue it is that you are experiencing.

Quick questions:

  1. I noticed that you said you could reproduce this issue in a clean project, could you provide a detailed set of steps in order to reproduce this issue on our end?
  2. Could you provide screen shots of all blueprints that may be involved with this issue?
  3. Could you provide any code that may be involved with this issue?

Hi,

I reproduced this issue by using the default c++ vehicle template. I disabled gravity in physics asset named “Sedan_PhysicsAsset” and then call SetActorLocation inside the vehicle pawn’s Tick function. SetActorLocation returns true and GetActorLocation returns the updated location but the visual is not updated. Please note that this use case works on 4.8.3 which I verified a couple minutes ago.

No blueprints involved.

Here is the simple test code:

void AVehicleTestPawn::Tick(float Delta)
{
	// Removed unrelated default code
        ....
    // Simple test code
	bool IsSuccessful = SetActorLocation(FVector(100, 500, 100));
	auto NewLocation = GetActorLocation();
}

Hello eozgonul,

Thank you for reporting this issue. I’ve been able to reproduce it and I’ve placed a bug into our database for the issue. For your reference, the bug number is UE-21300. Unfortunately I don’t have anything to suggest that you use in the meantime.

Have a nice day!

When calling SetActorLocation, be sure to specify the teleport option.

In Blueprints, there is now a checkbox for teleport. Simply check that box.

In c++ the 4th parameter is the teleport flag, so try:
SetActorLocation(FVector(100, 500, 100)),false,NULL,ETeleportType::TeleportPhysics);

Just in case my code has some differences from yours, can you follow up and let us know if that works? thanks.

Still does not work as it is supposed to, visual stutters a bit or the orientation of the vehicle changes even though the gravity is disabled. Please also note that this was working on 4.8.

The teleport doesn’t affect the velocity and spin. it just updates the position. so you might want to set clear these to 0.

Can you provide a bit of context on what is happening? Are you simulating a plane or a car somehow interacting with a plane? What is the frequency of calling setlocation. Typically, on a frame to frame basis, the common usage of the unreal car actor is to apply forces rather than setting the position directly. If you are calling setposition every tick, then you probably want to be doing this with a kinematic actor instead of a dynamic one (at least in the case of the root component).

I have a third party aircraft simulation library that takes control inputs and returns the position and rotation of the aircraft, thus I need to call SetActorLocation inside tick function. I need the default suspension and wheel roll ability for the aircraft, so I extend from AWheeledVehicle class.

I found this bug too,and i have a temporary solution:
before setactorlocation,set the vehicle mesh simulate physics OFF,and set vehicle movement to 0.
after you move the vehicle,set it back.

some of the changes to vehicles might have been the result of the addition of the teleport option as discussed here:
Moving Physical Objects - Unreal Engine

As shown in the comment below, the Set Simulate Physics with the checkbox not selected will make any of the parts that can be overridden to be kinematic. Consequently, any setlocation calls (without teleport) will cause those kinematic parts to move to the new location during the following physics update.

I still need to dig into the vehicle setup code to see if anything changed there, of if there’s something that needed to be changed as a result of the other changes to the movement system. to be continued.

couldn’t isolate when the change happened (content or code), but the component bodies on the car used to be also be kinematic, but somehow are now dynamic. This explains why the teleport behavior is still different than what was the case before. So, yes, set it to kinematic (turn off simultate physics), and hopefully that will be sufficient.

Thanks for the help. Will it be fixed back or this is how it is supposed to be used? One last thing, how much does it cost to switch physics off and on in Tick function?

The cost of toggling physics on and off shouldn’t be significant. When physics is “off”, the physics object still exists in the physics engine, its just controlled by your code and not PhysX - ie. “kinematically”. This is so that the object can push other dynamic objects out of the way.

When I tried it, I had turned physics enable off, but didn’t turn it back on. I suspect it might not actually do anything if you turn physics back on. That was the case with the version I tested. If you experience something different then there may be some added complexity to the Vehicle code or version differences I’m not aware of.

When you call SetActorLocation (non-teleport) on a kinematic object, it doesn’t move it right away. It sets a target position and waits for the next physics simulation step where it will then move to the new location. This way if the kinematic object is in contact with anything dynamic, it will push on them with the correct velocity resulting in the expected response from things that collide with it.