Place actor on his bottom bound - how?

When i drop items from my inventory, i want to place them on ground. So i do a Line Trace down and set its location to hit location. It works fine, but different items have different pivot points - which causes ‘sinking’ into the ground. How to place an actor on his bottom bound? Like that:

I’ve tried to “Get Local Bounds”, divide max value by 2 and add it as local position offset. It kinda worked, but some items have different pivot points and it causes them to, for example, float in air after applying this offset.

1 Like

I believe the magic you’re looking for is a node called “Get Actor Bounds”

An important parameter for me was to set the first to true so it would only pick colliding components. Like the OP I was doing some offset hacks on the CollisionVolume which worked inconsistently. Ideally the spawning box should already be on the floor so the hit test may be unnecessary in my case.

Here is a full example. The ASpawnVolume actor has a spawning UBoxComponent to define the volume.

void ASpawnVolume::SnapSpawnedActorToFloor(AActor* SpawnedActor) const
{
	auto SpawnPoint = SpawnedActor->GetActorLocation();
	SpawnPoint.Z = SpawningBox->GetComponentLocation().Z;

	FHitResult HitResult;

	// Avoid self-colliding
	FCollisionQueryParams CollisionQueryParams;
	CollisionQueryParams.AddIgnoredComponent(SpawningBox);
	CollisionQueryParams.AddIgnoredActor(SpawnedActor);

	bool bHit = GetWorld()->LineTraceSingleByChannel(
		HitResult,
		SpawnPoint,
		SpawnPoint - FVector(0.0f,0.0f, FloorTestExtent),
		ECollisionChannel::ECC_Visibility,
		CollisionQueryParams);

	if (bHit)
	{
		SpawnPoint.Z = HitResult.Location.Z;
	}

	FVector ActorOrigin;
	FVector BoxExtent;

	SpawnedActor->GetActorBounds(true, ActorOrigin, BoxExtent, false);

	SpawnPoint.Z += BoxExtent.Z;

	SpawnedActor->SetActorLocation(SpawnPoint);
}