How can I create a sticky mesh component which then sticks with two other unsticky mesh components? (VR/runtime)

Hi , I’m creating a VR game where the player should be able to freely create his own constructions. I would like to do this with a barely visible, flat sticky mesh component which sticks with two other unsticky mesh components. F.e. if the player wants to create a table it’s important that he can freely chose the position of a table leg upun the tabletop. So his first step would be to stick the sticky mesh component to the exact point on the tabletop where he wants the table leg to be placed. The second step would be that he places the tabel leg onto the sticky component. Does anyone know how to design such a sticky mesh component? Thank you!

It depends on whether you want your meshes to be connected in a elastic and dynamic way, like ragdolls, with physic simulation, or if you want your overall object to be rigid.

Does your project even implements physics?

Either ways, I would think about having this :

1 - objects containing a rigid assembly of static meshes (as components) → Let’s call it “RigidBody”

2 - your sticky magical object → Let’s call it “StickTool”

Your StickTool would have two RigidBody references - empty at spawn - and wouldn’t simulate physics at all. Whenever you place it on the first RigidBody, you put it in its first reference holder. Also, in the Tick event, you make sure that the relative transform of the StickTool to the RigidBody remains the same.

Then, when a second Rigidbody is brought in contact with the StickTool, you detect it and place it in the second reference holder. Then “connect it” (just teleporting in a few centimeters to match the faces properly).

Then, for the magic to happen, without waiting the next tick, you’ll have to merge the RigidBody’s together. For each staticMeshComponent of the second reference, you create a new and equivalent staticMeshComponent in the first reference. Then, you delete the second reference and the StickTool, so that what’s left is an assembled RigidBody with new parts.

Summary :

RigidBody, an actor with some StaticMeshComponents.
It simulates physics and collisions.

In its variables are an Array of StaticMeshComponents, in order to easily manipulate them.

It has a function that adds a new StaticMeshComponent to the array and place it at a specific relative transform, based on the relative transform of another RigidBody and the relative transform of the new meshComponent inside the other RigidBody.

You will have to develop great Transform functions, in order to manage the maths of everything.

StickTool, an actor with a StaticMeshComponent of small size.
It doesn’t simulate physics, but generates overlap events.

It has two variables : a reference to a first RigidBody, and a second RigidBody.

It can connect to a first RigidBody by storing its reference and by this time it will keep the same relative transform to this RigidBody.

Then a second RigidBody can be connected to it, stored in the second reference. As soon as it is done, it’s triggering the merging function of the first RigidBody which will copy every StaticMeshComponents of the second RigidBody into the first. Then, it destroys itself and the second RigidBody.

Hello CraftyWeazel thanks a lot for your fast answer! A really interesting idea to do this. In a first step they should only be rigid but phyics simulation should be activated. I’ll try it out and get back later.

Okay, keep me in touch :slight_smile: It’s an interesting project

Hello CraftyWeazel I wanted to ask you if you could give me an blueprint example on how to do the merging step.

“As soon as it is done, it’s triggering the merging function of the first RigidBody which will copy every StaticMeshComponents of the second RigidBody into the first. Then, it destroys itself and the second RigidBody.”

At the moment I create an array of all overlapping actors which should be merged by an event.

Thank you!

Hi!
I don’t have enough time to make an implementation, sorry, but I can give you some ideas :slight_smile:

“All overlapping actors” wouldn’t work there as it is only retrieving actors and not static mesh components, which are components in the second RigidBody.

When the second RigidBody is connected to the StickTool, try doing the following:

Get the RootComponent of the second RigidBody, get the array of all its Child components, and in a ForEach loop over that array, detect if each component if of type StaticMeshComponent (use a cast).

If that’s the case, you can do two things. Ideally, you would detach the StaticMeshComponent from the RootComponent and attach it back the the first RigidBody’s root component (keeping all coordinates relatives).

If that’s not possible, you would create a new StaticMeshComponent (there’s a node for that), set its StaticMesh and its Material the same, attach it to the first RigidBody’s RootComponent and then destroy the second RigidBody’s StaticMeshComponent.

Note: if you do the second option, either browse the array backward or delete StaticMeshComponents after having browsed the array or you would have some issues.

Thanks a lot for your fast answer !