Inherited capsule component placed inside ground

So I have a character blueprint and want it to be spawned through a spawner blueprint.

It now sometimes gets placed halfway into the ground and falls through. I can sense this is because the inherited capsule component goes halfway into the ground too. I can’t reposition it though, because it’s root / inherited.

I managed to solve this by adding the capsule’s half height as a local actor offset right after spawning it, but this doesn’t seem like a very clean solution. Is there a common way to deal with this?

Why is the capsules pivot point halfway into the ground anyways?

Maybe somehow placing the whole character into another blueprint, just so I can position it so the pivot point is not exactly at half the height? -.-’

You need to add the Characters’ Capsule Half Height additionally to the original Spawn Location’s Z.

1 Like

I have the same problem, did you find a cleaner solution?

I did the half height for now by using this code:

		UObject* Object = MyCharBlueprintClass->ClassDefaultObject;
		ACharacter* Character = Cast<ACharacter>(Object); // cast to your
		float capsuleHalfHeight = Character->GetCapsuleComponent()->GetScaledCapsuleHalfHeight();

Alternative code I used previously was the one below, but the one above is simpler and achieves the same result.

		// calculate half of the capsule height
		float capsuleHalfHeight = 0;
		UBlueprintGeneratedClass* ActorBlueprintGeneratedClass = Cast<UBlueprintGeneratedClass>(MyCharBlueprintClass);
		TSet<UActorComponent*> children = MyCharBlueprint->GetComponents();
		TSet<UActorComponent*>::TIterator iterComponents = children.CreateIterator();

		while (iterComponents) {

			UActorComponent* comp = *iterComponents;

			if (comp->GetClass() == UCapsuleComponent::StaticClass())
			{
				// Return cast USCS node's Template into your component class and return it, data's all there
				capsuleHalfHeight = Cast<UCapsuleComponent>(comp)->GetScaledCapsuleHalfHeight();
				break;
			}
			++iterComponents;
		}