Dynamically scale box based on min and max vector locations

I’m using an actor blueprint to dynamically scale a box mesh. However I want to be able to do so using 2 vector variables representing the opposite corners of the box (min and max vector variables). I can only scale the xyz in both negative and positive directions based on the box’s root. Is there a way to get around this? Is this possible with a static mesh or do I need to use some thing like a procedural mesh and define the vertices?

You do this with a static mesh, if the pivot point is in the corner.

If fact, all that’s really happening, is one vector parameter moves the corner, and the other scales the box from that corner.

But it would work exactly as you want.

PS: Not quite, but very close, I have to figure out some maths…

I’m not sure if that’s what I’m looking for? Based on my understanding of what you are saying it seems like I would able to choose to a root vector and then scale out from that root with another vector. But if moved the root vector then it wouldn’t rescale from that point, it would cause the whole box to move it’s location instead.

I tried to draw this out in two dimensions to better clarify. (please excuse my cocktail napkin drawing). I’m looking for two variable points, each of which would let me resize a box. In this 2D drawing, the Max vector and Min vector would each allow me to resize the rectangle’s size relative to other vector.

This sort of works. Only in a certain range at the moment.


But you can’t move the corners independently. It’s just a concept :slight_smile:

Procedural mesh might be easier…

The way to accomplish this is to start with a SceneComponent as the root of your actor, and then make the StaticMeshComponent be a child of that SceneComponent.

This will let you configure a component offset, rotation, and scale for your static mesh. Set the offset such that the center is the same as (Top + Bottom)*0.5 – the center of the corners.
Set the scale to be (Top - Bottom) / (BoxTopRight - BoxBottomLeft)

If you also need rotation, then this math needs to be done in the rotated coordinate space.

@ClockworkOcean thank you for the detailed response and documentation. Unfortunately it’s not quite what I’m looking for but I appreciate you putting this all together and it’s given me some ideas to think about.

@jwatte thanks for your response but I admit I’m having trouble translating it into a blueprint. I made a cube that’s a child of a scene component but I was confused if I was applying these changes to the transform to the cube or scene component. I also didn’t understand what the Top and Bottom were. Are they the isolated Z values of the BoxTopRight and BoxBottomLeft? This was my attempt to build what you were describing but I’m sure I am way off.

You put the offset bit into the Scene component. You put the scale bit on to Static Mesh component. If you need orientation other than that of the actor, you put that in the Scene component, too. The point of the approach is to separate out “where is the center and what is the reference frame” into the Scene component, which makes “how big is it and what does it look like” easy to do for the static mesh component.

Top and Bottom could just be two arbitrary corners.
If you want to guarantee that the scale of the box never goes negative along any axis, then Top is the Max() for each of the coordinates for the two specified corners, and Bottom is the Min() for each of the coordinates.