Set the position of an AActor relative to an other AActor

Hallo Community.

I do want to set the position of an AActor relative to an other AActors position.

  • when the actor A touches the actor B, the physical simulation of B will be deactivated, and B will move relatively to A.
  • Is it possible that actor A’s physics will also considers the mesh and weight of actor B?
  • In my opinion it would be possible to realise this while updating B’s position every tick. But this would be a massive wast of resources.

Is there a better way to realise this problem?

Ps. The overlap event and deactivating the physical simulation is not the problem. It’s all about the updating relative position of B.

Thank you very muche for your help!

Have you tried “attach to actor”?

Thank you very muche for your fast answer. Yes, I tried it. And you are right, this attaches the actor to the other actor.
Unfortunately dose this do not have any effect to the mesh. How can I bind the mesh to the actors component?

I use for the “attacher”:

    if(overlappingObjects.Num()>1){
        AActor* BasicObject = overlappingObjects[0];
        for(AActor* A:overlappingObjects){
            if(BasicObject!= A){
                
                A->AttachToActor(BasicObject,FAttachmentTransformRules(EAttachmentRule::KeepWorld, true));
                 
            }
        }
    }

And for the other object:

AStoneBrick::AStoneBrick()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

    this->Scene = CreateDefaultSubobject<USceneComponent>(TEXT("Scene"));
    this->RootComponent = Scene;

    this->ObjectMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
    this->ObjectMesh->AttachTo(RootComponent);
    this->ObjectMesh->SetSimulatePhysics(true);
    this->ObjectMesh->SetNotifyRigidBodyCollision(true);

}

**what am I doing wrong? **
Thank you very muche!