I made a rolling cabinet with three drawers (top, mid, bottom) which can be opened and closed individually by clicking on them.
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 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:
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”:
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…