-
Notifications
You must be signed in to change notification settings - Fork 15
Custom Shape Collisions

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
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

Important
Change your PushPawnBox to block PushPawn and ignore all other channels

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
Tip
Skip this if not implementing IPusheeInstigator on this Pawn, i.e. it may be a IPusheeTarget only
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 };
}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);
}Tip
For this section, you should have completed "Extend C++ Support for Blueprint"
Override Get Pushee Collision Shape

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
In your UPusheeComponentHelper Blueprint, override Update Pawn Owner and cache your character

Override GetPusheeCollisionShape:

You're all done!
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