Component bounds returning incorrect value for X. Also, halving the dimensions.

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?

Are you aware that the object bounds mean nothing if the object is rotated?

( I only read this quickly )

1 Like

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?

And just to check, the bounds are half the mesh size. I guess they’re measured from the middle. I assume it’s like ‘box extent’?

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?

1 Like

I just gave up and used a float to set the size :slight_smile:

What about spawning a separate copy of the mesh, just to measure the default bounds, then destroy it.

Then you can use that value in the spline :slight_smile:

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);

.cpp

void USupraFunctionLibrary::GetLocalExtents(UStaticMeshComponent* StaticMeshComponent, FVector& Origin, FVector& BoxExtent)
{
	if (IsValid(StaticMeshComponent))
	{
		UStaticMesh* StaticMesh = StaticMeshComponent->GetStaticMesh();
		if (IsValid(StaticMesh))
		{
			FBoxSphereBounds MeshBounds = StaticMesh->GetBounds();
			Origin = MeshBounds.Origin;
			BoxExtent = MeshBounds.BoxExtent;
			return;
		}
	}

	Origin = FVector();
	BoxExtent = FVector();
}

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 :slight_smile:

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!