Static mesh rotation

I’ve created a new C++ class using Actor as the parent class and only added a StaticMeshComponent:

UPROPERTY(EditDefaultsOnly, Category = Mesh)
class UStaticMeshComponent* TestMesh;

The constructor looks like this:

ATestActor::ATestActor()
{
// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

TestMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("TestMesh"));
TestMesh->bReceivesDecals = false;
TestMesh->CastShadow = false;
TestMesh->SetCollisionObjectType(ECC_WorldDynamic);
TestMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
TestMesh->SetCollisionResponseToAllChannels(ECR_Ignore);

RootComponent = TestMesh;
}

I then create a blueprint class from this C++ class and am spawning the actor into the world. When it spawns into the world it’s not facing in the right direction.

When editing the defaults (by double clicking the blueprint class) and looking at the static mesh in the viewport in the editor, I see that there is a Transform tab which has Relative Location and Relative Rotation but pressing the E key doesn’t allow me to visually rotate the mesh in the viewport. It looks like all of the W-E-R tools are grayed out and you can’t select them.

Could anyone explain why this is? Is there a way to visually rotate the mesh in the viewport or is my only option to specify values manually?

Try adding BlueprintReadWrite to the UPROPERTY() statement. Seems the Edit* ones affect the main editor and the Blueprint* ones affect the blueprint editor. It was always a bit confusing to me. I just used BlueprintReadWrite and EditAnywhere all the time. Glad I looked into it for you. Cheers.

Can you change the values manually in the Details window when you select it?
You could try this: https://forums.unrealengine.com/development-discussion/content-creation/4520-transform-axis-disappeared.

I tried but it didn’t work for me. I even tried (EditAnywhere, BlueprintReadWrite, Category = Mesh) and it still won’t let me use the W-E-R tools in the viewport. I set a static mesh and when I click it, it shows the yellow border but the tools are still grayed out.

Yup, I can change Relative Location, Relative Rotation, and Relative Scale 3D in the side window bar on the right. I’m having trouble finding those options but I found an option Editor Preferences - Level Editor - Viewports - Enable Combined Translate/Rotate Widget but checking it didn’t seem to help.

Here is a screenshot of what my editor window looks like. You can see the “Relative” options on the right tab there but the W-E-R tools grayed out.

That seemed to fix it, marking this as the answer. How do you usually create a basic actor with a static mesh without using the “default root node”? You said you’ve never done it this way before and I’m still learning the basics. :slight_smile:

Oh. That’s because it’s the root component. The root can’t be rotated there because it’s rotation is in the world. If you add sub-components to it, you will be able to rotate them relative to your mesh – not that you want to, just that’s how it works. In other words, the root component’s rotation is the actor’s rotation.

What you need is a “Default root node”. I’ve never done that before but… In your class, add a Scene Component, call it “DefaultSceneRoot” cuz that’s what the UE4 default name is. In your constructor, add “Root = DefaultSceneRoot”. Then call “TestMesh->SetupAttachment(DefaultSceneRoot);”

I think that’s how you do it.

It’s not a mesh thing. This is how it is for any component. If you need a component to be rotated independently from the actor then it can’t be the root node. Similarly, if you call things like SetRelativeLocation() on a root component it will do the same thing as calling SetWorldLocation().

If all you have is a mesh then there’s no reason to rotate it in the blueprint viewport. You can just plop or spawn the actor in the world and rotate the actor. The mesh will rotate along with it. So you don’t really need a separate root object. You only need that if you want to rotate the mesh independently from whatever else is in the actor.

If you only need to orient the mesh so it’s facing ‘forward’ then you can edit the mesh asset and change “Import Rotation”, then select “Asset->Reimport …” from the file menu.

Good luck with the rest of your endeavor.