Attaching actor to actor at runtime on Hit location

I am looking for solution to attach one actor to another. I am working with something similar to minecraft block placing.
I have actor class Voxel, and when my Raycast (Hit) hit another voxel it should attach them.

But I don’t know how to do it properly.
My code:

AVoxel* const Voxel = World->SpawnActor<AVoxel>(VoxelClass, Hit.ImpactPoint, *NoRotation, SpawnParams);
Voxel->AttachRootComponentToActor(Hit.GetActor());

But it not work :frowning:

But it not work for RigidBody. :frowning:
I need to move acotrs by pushing them by PlayerCharacter. So what is solution for that? :smiley:

Hi Xender,

To attach actor to actor try this

MyActor1->AttachRootComponentToActor(MyActor2, NAME_None, EAttachLocation::KeepWorldPosition);

Also actor should be movable.

Best regards,

But it not work for RigidBody. :frowning:
I need to move acotrs by pushing them by PlayerCharacter. So what is solution for that?

Hi Xender,

Try to use UPhysicsHandleComponent

// Create component
PhysicsGrabber = PCIP.CreateDefaultSubobject<UPhysicsHandleComponent>(this, TEXT("PhysComp"));

// Update
PhysicsGrabber->SetTargetLocationAndRotation(DesiredPosition, DsiredRotation);

// Lost grabbing component
PhysicsGrabber->ReleaseComponent();

Best regards,

This how its like in my app:

and i dont know why.

Hi Xender,

Not sure that I correctly understand what’s going on video. On 11 second I see you threw box. If you are using UPhysicsHandleComponent in this moment I think you set up target location that is far from current box position. On 23 second I think you spawn box inside another boxes. Like a result physics try to fix geometry penetration.

Check QAGame example. There is example of using UPhysicsHandleComponent component.

Best regards,