Skip to content

Custom Shape Collisions

Jared Taylor edited this page Mar 22, 2025 · 8 revisions

UnrealEditor-Win64-DebugGame_2024-10-22_17-46-56

Important

This covers any use-case where a separate shape is used instead of the root component
Horizontal capsule or Box collisions for characters will be the most common use-case
Supports spheres and non-character Pawns too

Note

This guide assumes you already have PushPawn setup and fully functional

Tip

Available to C++ and Blueprint

Add a Collider

Start by adding the shape component you wish to use to your Pawn:

  • BoxComponent
  • CapsuleComponent
  • SphereComponent

This should generally be parented under your root component. For the sake of this guide, it is a UBoxComponent named PushPawnBox.

Important

Change your root CapsuleComponent to ignore PushPawn

UnrealEditor-Win64-DebugGame_2024-10-22_17-12-23

Important

Change your PushPawnBox to block PushPawn and ignore all other channels

UnrealEditor-Win64-DebugGame_2024-10-22_17-14-08

Note

It may be appropriate to set the PushPawnBox ObjectType to Pawn, but it does not matter

Tip

Creating collision profiles may be cleaner than directly changing the blueprint

Pushee

Tip

Skip this if not implementing IPusheeInstigator on this Pawn, i.e. it may be a IPusheeTarget only

Extend C++ Support for Blueprint

Note

If you are using a C++ only project, you may find it worthwhile to make a function blueprint can override
This is entirely optional

Add the following helper function and blueprint function:

UFUNCTION(BlueprintPure, BlueprintImplementableEvent, Category=PushPawn, meta=(DisplayName="Get Pushee Collision Shape"))
FPushPawnCollisionShapeHelper K2_GetPusheeCollisionShape() const;

UFUNCTION(BlueprintPure, Category=PushPawn, meta=(DisplayName="Get Default Pushee Collision Shape"))
FPushPawnCollisionShapeHelper K2_GetDefaultPusheeCollisionShape(EPushCollisionType OptionalShapeType = EPushCollisionType::None, USceneComponent* OptionalComponent = nullptr) const;

Update the function definition to return it:

FCollisionShape AMyCharacter::GetPusheeCollisionShape() const
{
	return K2_GetPusheeCollisionShape().ToCollisionShape();
}

Implement the helper function:

FPushPawnCollisionShapeHelper AMyCharacter::K2_GetDefaultPusheeCollisionShape(EPushCollisionType OptionalShapeType,
	USceneComponent* OptionalComponent) const
{
	FCollisionShape Shape = UPushStatics::GetDefaultPusheeCollisionShape(this, OptionalShapeType, OptionalComponent);
	return FPushPawnCollisionShapeHelper { Shape };
}

C++

Tip

If you completed "Extend C++ Support for Blueprint" then go to "C++ with Blueprint Support" Override GetPusheeCollisionShape:

FCollisionShape AMyCharacter::GetPusheeCollisionShape() const
{
	return UPushStatics::GetDefaultPusheeCollisionShape(this, EPushCollisionType::Box, PushPawnBox);
}

C++ with Blueprint Support

Tip

For this section, you should have completed "Extend C++ Support for Blueprint"

Override Get Pushee Collision Shape

UnrealEditor-Win64-DebugGame_2024-10-24_17-12-04

Tip

Specifying the OptionalBoxShape is a performance boost, because it doesn't need to check the type

Caution

Specifying the wrong OptionalShapeType will crash the engine
This is intentional, and not a bug

Blueprint

In your UPusheeComponentHelper Blueprint, override Update Pawn Owner and cache your character

UnrealEditor-Win64-DebugGame_2024-10-22_16-50-23

Override GetPusheeCollisionShape: UnrealEditor-Win64-DebugGame_2024-10-22_17-55-54

You're all done!

Testing

You can use p.PushPawn.Scan.Debug.Draw 1 console command to draw the shape used to scan.

Warning

If your scan shape does not match the box shape it is probably because PusheeRadiusScalar on your scan ability is not 1.0

Clone this wiki locally