Does UE4 supply a collision component

Hi,

In my 2D game, I have setup collision successfully so that I can shoot an alien with my spaceship laser. I’ve created a box component as my root component on my alien sprite and implemented the overlap delegate function. So far so good.

My question is this. If my sprite is setup as “Tight Bounding Box” as the Collision Geometry Type in the sprite details screen, then surely UE4 must have setup these details somewhere in the code or asset? Why do I need to create my own custom box component?

I have asked this type of question before. I actually want to use “Shrink Wrapped” collision, but do I have access to this configuration information in my C++ actor?

I have tried setting up overlap checks on the primitive component (which I get with FindComponentByClass<UPrimitiveComponent>()), but collision doesn’t work on it.

If UE4 does not supply a collision component, then I’m thinking I could add additional box components to my actor, with smaller box regions, to get pixel perfect type collision.

How do others do pixel perfect collision using Paper2D?

Thanks in advance,
M.

Create an invisible/simple mesh as the root component, with a more detailed collision mesh. (you can do this in a 3d program or just manually do it in unreal mesh editor and add and remove/resize collision shapes or use the auto generate collision feature)

Remember, the core design behind unreal is 3D, and mostly a 3D fps, but it can do alot of other things as well, such as 2d etc. The basic concept is Artists create content for unreal engine with 3d programs, and you import the data, mesh and collision and all.

If you are going to do 2D, you will have to create 2d mesh’s with good collision data to get accurate collisions. So a bunch of collision boxes/shapes or use 3d program to do all the work.

Alot of people end up using GameMaker Studio instead since it’s easier and more straight forward for 2D concept style games.

Thank you for your advice. You got me thinking and I made a wonderful discovery! Something useful for others using Paper2D …

I don’t need a custom box component after all! I am coding in C++, so here are the details:

UPaperSpriteComponent and UPaperFlipbookComponent are inherited from UMeshComponent, so they do in fact come with built in collision!

The sprite asset contains the collision details, e.g. I set my sprite to Shrink Wrapped and a Collision Thickness of 1.0 and by default the component already has Generate Overlap Events set to true and all I needed to do was set the Collision Presets to OverlapAll, i.e.

MySpriteComponent->SetCollisionProfileName(“OverlapAll”);

where MySpriteComponent is a flipbook component.

Then do the usual overlap delegate function setting, but on the actual flipbook component, i.e.

MySpriteComponent->OnComponentBeginOverlap.AddDynamic(this, &AActor1::OnBeginOverlap);

Be sure to set the flipbook to First Frame Collision or Each Frame Collision.

The exact same is true for a sprite component.

For those that want the delegate function details, here they are:

In your .h class definition have:

public:
UFUNCTION()
void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

and in your .cpp file have:

void AActor1::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr))
{
if (OtherActor->GetClass() == AActor2::StaticClass())
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, FString::Printf(TEXT(“Actor1: Actor2 overlapped with me!”)));
}
}
}

This function basically checks if AActor2 has overlapped AActor1 and prints a debug message.