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?