Download

How to organise a pawn with multiple static meshes

My player pawn is a tank-like object with a separate mesh for base, middle and “head”. Each part needs to be rotated via code (C++) but each needs to connect to the piece below, so when the base moves the middle moves with it, etc. The meshes are physics-enabled, so the pawn will move by applying force to the base in the direction it is facing. A Blueprint subclass is used to organise the meshes.

I’d like to know how these meshes should be connected. Am I looking at a physics constraint between each mesh?

Any suggestions would be welcomed.

I would suggest looking in to adding skeletal mesh sockets.

If you look in your player pawn viewport tab you should see what ever you added to that BP. Lets say that it’s the base. You can then drag and drop the middle section as an inherited sub component of the base and then added the head as an inherited sub component of the middle section.
As the base component turns so does all of the inherited components but you can still rotate each of the parts as being unique (ie turn the middle the head will turn but the base won’t)

Hey Frankie; that’s a very good point and something I did not think of. I have also been pointed towards creating a Modular Pawn, using Skeletal Meshes, however your idea is very simple. Many thanks - I will try this out over the w/e.

Frankie; OK I’ve given this a try and it looks to be exactly what I want with the exception that I am unable to set “Simulate Physics” on any of the meshes, despite them having Collision Meshes set.

As a test I took one of the meshes and created a Blueprint from it, as I was able to set “Simulate Physics”, so the meshes seem set-up just fine.

The only way I can get physics is by adding a collision object (a box for example) as a separate item in the blueprint, and even then it seem to behave quite right.

Could this be due to how I’m creating the UStaticMeshComponents in the Pawn C++ class, perhaps?

I’m using:

[FONT=Courier New]RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT(“RootComponent”));
BaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(“BaseMesh”));
BaseMesh->AttachTo(RootComponent);
BodyMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(“BodyMesh”));
BodyMesh->AttachTo(BaseMesh);
HeadMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(“HeadMesh”));
HeadMesh->AttachTo(BodyMesh);

Edit Further debugging. I added some logging in the BeginPlay() method and it looks like the editor should be able set “Simulate Physics”:

[FONT=Courier New]void AHeroPawn::BeginPlay()
{
Super::BeginPlay();

UE_LOG(LogTemp, Log, TEXT("BaseMesh can simulate physics: %s"), (BaseMesh-&gt;CanEditSimulatePhysics() ? TEXT("YES") : TEXT("NO")));
UE_LOG(LogTemp, Log, TEXT("BodyMesh can simulate physics: %s"), (BodyMesh-&gt;CanEditSimulatePhysics() ? TEXT("YES") : TEXT("NO")));
UE_LOG(LogTemp, Log, TEXT("HeadMesh can simulate physics: %s"), (HeadMesh-&gt;CanEditSimulatePhysics() ? TEXT("YES") : TEXT("NO")));

}

and got this:

[FONT=Courier New]LogTemp: BaseMesh can simulate physics: YES
LogTemp: BodyMesh can simulate physics: YES
LogTemp: HeadMesh can simulate physics: YES

However there is no “Simulate Physics” setting in the Physics section:

00f655e4bfdc1b1d0dcc07a9a6ccbd71e3a88d5b.png

I second the suggestion to try sockets, though I’m not actually sure if you can change the rotation of an object if it’s welded to another. I believe, the only other option is a physics constraint, which should work fine. The only drawback to constraints is they’re not “perfect”, but presumably you’re not swinging your tank-like object around like crazy, so you should be good.