I wanted a way to measure a mesh that can be changed (Instance Editable) in order to dynamically input the correct spacing in my spline mesh BP instead of having to manually enter a value. I thought I could use Get Component Bounds for this and just grab the bounds of my Spline Mesh, but this doesn’t seem to work:
For whatever reason it always returns the wrong value for X. If I get the actor bounds from a spawned actor, the dimensions are halved.
What am I doing wrong? Is there a different way to get the dimensions of a mesh?
I gathered that after watching a tutorial on it last night. In this case, however, it’s perfectly straight and still giving the wrong values. So how does one get the measurements of a mesh then?
Makes sense. Still confused why the X is the only value that’s wrong. I also did some further testing and it’s returning different values depending on the positioning of the actor, so as you said getting bounds is not an accurate way to get the mesh dimensions.
Is there another way to get this info? Maybe directly from the file?
Extent is “Extent from the origin” and it extends that amount in the + and - directions from the origin. So it is going to be half the size of the box along that axis.
The extents will be in reference to the world XYZ axis. So rotation of a component will change the bounding box “Extent” of the mesh.
I have this C++ function that I use in multiple projects and situations.
Which returns the Extent information for a mesh in its own local space.
This information you can then transform to world space with the mesh component’s WorldTransform.
.h
/** Get Local extents */
UFUNCTION(BlueprintCallable, Category = "Components|StaticMesh")
static void GetLocalExtents(UStaticMeshComponent* StaticMeshComponent, FVector& Origin, FVector& BoxExtent);
I contemplated that. To be honest, I did the same because I can’t be arsed. I guess that’s why everyone uses a float as opposed to getting the dimensions dynamically
I noticed there’s also a GetComponentLocal Bounds but this returns a Min and Max value and I didn’t know how to get the extent from them or really what to do with them mathematically. I’m not a C++ programmer yet, so I’ll have to keep this in mind for the future. Thanks for sharing Ben!