How to change the pivot point of static mesh using c++?

Hi there, so basically question is in the title. Can anybody tell me how to do that using c++ as I created static mesh using c++ and pivot point is on the bottom of the object and I want it be in the middle.
Thank you

The problem is the mesh that you are using, since they made it with the pivot on the bottom, so it’s fairly simple, just get the static mesh component on that actor and move it by half it’s height.

I’m not near my computer but you can do something like this (If you are inside the actor we are talking about):

FVector bounds = StaticMeshComponent->GetBounds(); //Move the static mesh on the Z direction only StaticMeshComponent->SetComponentLocation(0.f, 0.f, -bounds.Z * 0.5f);

As I said I’m not near my PC so I cannot test this, but GetBounds() should give you the width, height and depth of the mesh, just adjust the location of it and you will have the pivot in the center.

I get your idea and it seems to be good, but there is the problem. Static component doesn’t seems to have GetBounds() function, only GetLocalBounds() which take two parameters (FVector min and Fvector max) and I dont know what should I put for those min and max?

I came across this similar question in which they are using GetActorBounds (Link below), In any case I was checking the GetLocalBounds and it takes two “out” parameters, whenever you see a function asking you for a parameter as a reference in which you know you should get something in return that means that those parameters that you will pass into the function will be modified inside of it, it’s a very common practice in Unreal because you can call a function to return more than just one value out of it, in this case just create two FVectors and init them to cero, pass them into the function and after calling it check out their values and you will see they got updated. How do I get the size of a static mesh? - Asset Creation - Unreal Engine Forums

1 Like