How can I make my boxes connect when they are hit?

Hello everyone, I am trying to make my boxes attach everytime they are hit. I did a system but it doesn’t connect everytime. If both boxes are attached, then it just can’t connect. I tried to connect their parents, but it made the system way worse. When parent connects, other attach just expires. What should I do?

Hi Welcome to the community,

So as I understood its 4 5 6 many many boxes attached.

When you hit a box and you try to connect to that group , if they share one shared parent everything will work. AttachTo(SharedParent)

If these are actors, you can put a SharedParent variable as actor. Before you attach check if SharedParent is valid, if so attach to that one and keep world. If its not valid you can connect directly to hit actor.

If the box(es) you have have already have shared parents (Trying Attaching group of boxes to boxes) then you also need to check if GroupA->SharedParent != GroupB->SharedParent then one has to be master and that moment you have to loop all to the new parent and re attach.


Another approach , If these are not actors in your system/ structure. You can simply have a AttachmentManager with a dictionary and you can book keep in an TMAP of objects. After you make an attachment, you can check first the TMap if they exist, if not you create an entry so that we can trackt the record of what is connected to what.

The next hit and attachment you check this TMap again and you find the object already connected, you get their shared parent and attach to that one.

This last approach would be better in long term, if this become a core game mechanic and scales better however the first approach would be much faster to create imo.

Let me know about it.

What do you mean by shared parent?

Meaning that all childs connect to same parent (one actor becomes parent of all )

You can also btw if you show a video of what you are trying to do , we can be more helpfull, even if its not working its important for us to understand problem clearly and deeply.

Second Actor variable checks if hit actor is the one I plugged the second socket (circles i attach to boxes, they make boxes pull themselves) in. It works if I plug second box in triology to a box, but doesn’t work if I try to plug other box to second box. I worded it bad, you can see it on video anyways. Also just noticed that if I remove second actor in blueprint, it works just fine but then it can attach with any box.

1 Like

Okay I get it now. So apparently second actor check fails because if it hits the box, it acts like it hit the parent

Well yes, so when hit put a variable inside BP_Box as “SharedParent”

If this “SharedParent”->IsValid

->True ->AttachTo(SharedParent)
->False->Attach to (AnyOfThem as Parent) but also set their SharedParent.