How to use the construction blueprint properly to set open/closed drawers for my cabinet?

I made a rolling cabinet with three drawers (top, mid, bottom) which can be opened and closed individually by clicking on them.
image

It is composed of 4 static meshes. The frame and the 3 separate drawers. I added some logic to the construction script of this blueprint so that I can set the drawers to be open or close in the Unreal Editor. I do this by having an instance editable variable “IsOpen” for each drawer. If this boolean is set to true in the editor, a local offset in the X direction is added to open the drawer.

My construction script works as it is supposed to, but I can’t shake the feeling that there must be a better, more logical/readable way to achieve what I’m doing, since I’m using a bunch of chained branches for each and every drawer.

The Macro is just the set local offset with a split pin structure that only affects the X-value.
image

If I were to have a big sorting cabinet like this one in metro, I’d have a big problem using this logic, since it is not really scaleable.
image

So with future projects in mind, I would like to know if this is a legitimate way to do this or if there is a better way I’m too blind to see.

Hi ecksdeeeee,

That’s looking good!

For a lot of drawers, you could create a TArray of structs (the struct would have a bool for “isOpen”, a “Slide Distance” and a Mesh pointer).

Then you could just do a “For Each” loop on that TArray and process each one in that loop…

1 Like

The more direct way, is to use ‘set relative location’ for each drawer in the construction script. Notice, you only need to set one coordinate, the other two stay the same.

So how would that work in practice? I have created a TArray variable, but I don’t know how to specify it’s size, it’s internal structure and how to fill it with data.

My guess would be that a TArray would basically be like an array in numpy (python). So let’s say I have 10 drawers and for each I have a SM Component pointer, a bool and a move distance. So it would kind of look like this:
Pseudo code:

TArray Drawers = TArray(((pointer0,bool0,dist0), (pointer1,bool1,dist1)), ..., (pointerN,boolN,distN))

So it would have the shape of Nx3 and could be indexed or something? All I see in here when I add a TArray as a variable is the following:

I do not know how to go from here, especially since I’m working in Blueprint only.

It’s very much like the Arrays you’ve used.

First step is to create the Blueprint Structure:
image

Then, in your Chest of Drawers Blueprint, you can then add an Array of those - add a variable, set it’s type to the struct you just created, and set the icon besides that to “Array”:
image
Then you can add each drawer to that array in a little bit of Blueprint like:

If there’s a lot of them, you could make a routine that calls “GetChildComponents” of StaticMesh and ForEach through those, adding them - there’s many ways you could do that side.

Also, ClockworkOcean is correct about the “Relative Location” part - that will make it easier…