Start dragging of mesh from code


Luckily its super easy to create dragable meshes.
But I want to trigger the drag without the need of a click. For example I would like to start the dragging when the scene is loaded.

Is this possible?

My real case is a bit different, but the concept should stay the same.
I have an html button positioned over my canvas (my ui) and on click I want to generate an object (which is no problem) and then have it attached to the mouse so it can be placed in the scene with one more click.

Best Regards

Is this possible?

Welcome to the forum !!!

You can call the startDrag method on the behavior for this :

1 Like

Ohh its that easy, thanks. I thought I tried this method already but seems like I did something wrong.

1 Like

I didn’t see the solution in

So i made this. Essentially just start drag with any pointer Id.

The solution is to call pointerDragBehavior.startDrag(); when you want to start dragging.