Possessing an Actor after Detaching

Hey everbody,

I got a problem that I dont quite understand:

I am trying to programm a routine where a third person character is able to enter the buggy from the UE Starter Content (Advanced Vehicle Example), drive around and leave it again. Now, entering the Buggy works like a charm:

if (overlappingEnterActors.Num() == 1)
	{
		ATP_VehicleAdvPawn* vehicle = Cast<ATP_VehicleAdvPawn>(overlappingEnterActors[0]);
		check(vehicle);
		
		if (GetWorld()->GetFirstPlayerController() != NULL)
		{
			if (GetWorld()->GetFirstPlayerController()->WasInputKeyJustPressed(EKeys::E))
			{				
				this->SetActorEnableCollision(false);
				Cast<ATP_VehicleAdvPawn>(overlappingEnterActors[0])->driver = this;
				this->AttachToComponent(overlappingEnterActors[0]->GetRootComponent(),FAttachmentTransformRules::SnapToTargetNotIncludingScale);
				GetWorld()->GetFirstPlayerController()->Possess(Cast<ATP_VehicleAdvPawn>(overlappingEnterActors[0]));
			}
		}
	}

Now the actual problem is: When I have the Character attached to the buggy and press the assigned action button to leave it again I thought it would work like that → Set location of Character → Enable Collision → Detach it → Posses it.

Setting location, detaching and possesing works fine as long as I do not set actor collision back to true:

driver->SetActorRelativeLocation(FVector(0.0f, -100.0f, 50.0f));
driver->DetachRootComponentFromParent();
GetWorld()->GetFirstPlayerController()->Possess(driver);

The Problem now of course is that as soon as I move with the character it falls through the ground. When I include collision activation the posses does not work anymore and I am still controlling the buggy.

driver->SetActorRelativeLocation(FVector(0.0f, -100.0f, 50.0f));
driver->SetActorEnableCollision(true);
driver->DetachRootComponentFromParent();
GetWorld()->GetFirstPlayerController()->Possess(driver);

Would be great if someone could help me out. Still new to the engine :slight_smile: Thank you so much for your help!

Greetz,

Max