Lock Pawns Movement to WheeledVehicle


I have an object which should be always on the roof of my wheeled vehicle.
At the moment I spawn it where the car is and move it with the car every tick. This does not work because of the tend and tilt of the car.
Because currently it is fixed to the “center” of the point it does not care for the tilt.
Is it possible to lock it physically to the car so it moves with it and I do not have to do anything for it?
Im pretty new to Unreal C++. My car based on WheeledVehicle.

So when the car spawns it get the function SpawnRoofObjects() which currently looks like this:
Spawn object with GetWorld()->SpawnActorDeferred …
Set a controller to the pawn just spawned.
Then every tick get the cars currentLocation and move the object.

How to lock it on the roof (or anywhere else)

Thanks a lot for helping!

Have you tried using AttachToComponent()?

Get the actor controlled by the pawn and call AttachToComponent on it, setting the actor’s parent to your vehicle. If your vehicle has sockets, you can even attach the pawn’s actor to a specific socket.


AActor* PawnActor = <get the actor for your pawn>
AActor* VehicleActor = <get the actor for your vehicle>

PawnActor->AttachToComponent(VehicleActor->GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);

Play around with the parameters and components if you like. This should get you the desired result, with the pawn now attached to the vehicle. Moving the vehicle will automatically move the pawn along with it.

Exactly what I was looking for. Thanks a lot, works great now. I created a socket at the position I need and attached it to my pawn.