How to fill gap between objects by moving neighboring objects?

Lets say you have a shelf filled with books and you want to replace a large book with a thin book object (within the editor - not during gameplay). If you replace the mesh, there will be a gap in space on either side. How can I go about shifting all the books on both sides to close the gap?
Likewise, how would you shift all the neighboring book objects if you replace one of them with a larger mesh, resulting in overlapping meshes.
I would assume putting all the meshes into an array and use a foreach loop to move the objects (except the replaced mesh) the same value to the left or right of the object, but what would you use to determine the gap/overlapping space? Bounding box? Collision box?

if its just placing in the scene then i would do it manually. if you really wanted to do it via blueprint then you could use book one as the anchor/ origin point and have that placed then you could use a for each for all the rest of the books and have a script that uses a line trace to determine the edge of one book and give you the location to place the next book. something like the following. of course thats just one way, theres probably a better method though.

Thanks, I will try playing around with that and see where it gets me.
Yes, a BP is what I am looking for as the example I gave is very simple. Imagine if you had scores of books on a large bookshelf… like in a Library. Then a BP would be much easier to use despite it taking longer to implement during development.

possibly using sockets? I have never used them but they do quite well from what I hear about “attaching” components and actors to other components and actors. Attaching a weapon to a player’s hand for example is done using sockets, I am sure it would be a relatively minor adjustment to get it to do the same for attaching a book to another book.

If you do this you will also have to account for the size of each book. Consider making the size of each object a multiple of a certain number of units this way you can just move them incrementally.