How to enable collision on a Pawn?

Hello,

I have a Pawn that is basically just a point camera, I’d like to have this pawn bump into walls, and things like that. It’s my understanding that a USphereComponent can do this.

So I added a USphereComponent to my Pawn…

The header…

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/Pawn.h"
#include "VehicleEditorPawn.generated.h"

UCLASS()
class EDITOR4_API AVehicleEditorPawn : public APawn
{
	GENERATED_BODY()

public:

	AVehicleEditorPawn();

	virtual void BeginPlay() override;

	virtual void Tick(float DeltaSeconds) override;

	virtual void SetupPlayerInputComponent(class UInputComponent *) override;

	void OnConstruction(const FTransform &) override;

	UFUNCTION(BlueprintCallable, Category = "Physics")
		void OnHit(AActor * SelfActor, UPrimitiveComponent * OtherActor, FVector NormalImpulse, const FHitResult& Hit);

	// ...

And the cpp…

AVehicleEditorPawn::AVehicleEditorPawn()
{
	// 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;

	// Create and attach the scene component to root
	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root Component"));

	// Create and setup the camera
	CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera Component"));
	CameraComponent->AttachTo(RootComponent);

	// Create and setup the sphere collision component
	SphereCollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Collision Component"));
	SphereCollisionComponent->AttachTo(RootComponent);
	SphereCollisionComponent->SetSphereRadius(20.f);
SphereCollisionComponent->BodyInstance.SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics, true);
SphereCollisionComponent->OnComponentHit.AddDynamic(this, &AVehicleEditorPawn::OnHit);

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

void AVehicleEditorPawn::OnHit(AActor * SelfActor, UPrimitiveComponent * OtherActor, FVector NormalImpulse, const FHitResult& Hit)
{
	GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Red, FString::Printf(TEXT("Hit")));
	UE_LOG(LogTemp, Warning, TEXT("HIT!"));
}

But the delegate isn’t getting called. I think I haven’t properly configured the body object.

Make sur hit events are ensbled

SphereCollisionComponent->SetNotifyRigidBodyCollision(true)

It’s still not working…

SphereCollisionComponent->SetCollisionProfileName(“Pawn”)

The reason for this is because all collisions are processed via the root component. After collision processing is finished, child components are teleported to the end location. Your root component is a USceneComponent which has no collision properties in and of itself. If you change the root component to be a USphereComponent, UStaticMeshComponent, or something similar, then that object will process the collision accordingly. I remember being told by staff that you could potentially change which component processes collisions (to NOT be the root component), but then everything above that component in the hierarchy would not move or not collide or something of the sort (i.e. will become glitchy).

OK gave that a whirl, still not working…

// Sets default values
AVehicleEditorPawn::AVehicleEditorPawn()
{
	PrimaryActorTick.bCanEverTick = true;

	// Create and attach the scene component to root
	SphereCollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Collision Component"));
	RootComponent = SphereCollisionComponent;

	// Create and setup the camera
	CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera Component"));
	CameraComponent->AttachTo(RootComponent);

	// Create and setup the sphere collision component
	SphereCollisionComponent->SetSphereRadius(50.f);
	SphereCollisionComponent->SetNotifyRigidBodyCollision(true);
	SphereCollisionComponent->OnComponentHit.AddDynamic(this, &AVehicleEditorPawn::OnHit);

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

set collision profile name
SphereCollisionComponent->SetCollisionProfileName(“Pawn”)

AVehicleEditorPawn::AVehicleEditorPawn()
{
// 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;

	// Create and attach the scene component to root
	//RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root Component"));
	SphereCollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Collision Component"));
	RootComponent = SphereCollisionComponent;

	// Create and setup the camera
	CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera Component"));
	CameraComponent->AttachTo(RootComponent);

	// Create and setup the sphere collision component
	//SphereCollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Collision Component"));
	//SphereCollisionComponent->AttachTo(RootComponent);
	SphereCollisionComponent->SetSphereRadius(50.f);
	SphereCollisionComponent->SetNotifyRigidBodyCollision(true);
	SphereCollisionComponent->SetCollisionProfileName("Pawn");
	SphereCollisionComponent->OnComponentHit.AddDynamic(this, &AVehicleEditorPawn::OnHit);

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

Did this, tested against a box and BSP. Still nothing.

Test collision with no physic simulated objects works only with CharacterMovement component (where root is main object which collide to another), or ProjectileMovement component (here you can use SetUpdatedComponent and choose component which need to collide).