Go through the floor

I’m learning Unreal and now I’m trying to understand how collisions work.

I have created an empty C++ project with the default map and added a class that I can move with keyboard. When I move it I have found that my Pawn can go through the floor:

116431-through-floor.png

My Pawn constructor is:

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

	// Our root component will be a box that reacts to physics and to interact with physical world.
	UBoxComponent* BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxComponent"));
	RootComponent = BoxComponent;

	// Create and position a mesh component so we can see where our sphere is.
	UStaticMeshComponent* MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PaddleVisualRepresentation"));
	MeshComponent->SetupAttachment(RootComponent);

	// Add a visual cuboid to see it.
	static ConstructorHelpers::FObjectFinder<UStaticMesh> CuboidVisualAsset(TEXT("/Engine/EditorMeshes/EditorCube.EditorCube"));
	if (CuboidVisualAsset.Succeeded())
	{
		MeshComponent->SetStaticMesh(CuboidVisualAsset.Object);
		static ConstructorHelpers::FObjectFinder<UMaterial> GreenGrassMaterial (TEXT("/Game/Materials/M_Grass.M_Grass"));
		if (GreenGrassMaterial.Succeeded())
		{
			MeshComponent->SetMaterial(0, GreenGrassMaterial.Object);
		}
	}

	// Take control of the default player
	AutoPossessPlayer = EAutoReceiveInput::Player0;

	// Create an instance of our movement component, and tell it to update our root component.
	OurMovementComponent = CreateDefaultSubobject<UPaddleMovementComponent>(TEXT("PaddleCustomMovementComponent"));
	OurMovementComponent->UpdatedComponent = RootComponent;
}

How can avoid it?

Collision works on channels. You need to have a collision volume WITH collision enabled and you need to be blocking the same channel.

When teleporting the mesh you have to turn on sweep to check if you hit anything. If you did you have to handle the collision.

If you use a standard controller you must just make sure that the world AND your cuboid have active collision, EnableCollision(true) I believe, and both set to BlockAll.

HTH

Thanks. The BoxComponent was smaller than the visual component. I’ve fixed it adding this line: BoxComponent->InitBoxExtent(FVector(100.0f, 100.0f, 100.0f)); and also setting BlockAll.