I am coding (and learning UE4) a game in C++ using Paper2D and I am having trouble getting collision to work.
In my simple scenario I have a flipbook component (enemy) and I want it to fire my delegate if another sprite component (laser) overlaps it.
Here is a snippet of my code:
[FONT=courier new]Enemy = CreateDefaultSubobject<UPaperFlipbookComponent>(TEXT(“Enemy”));
Sprite = Cast<UPaperFlipbook>(StaticLoadObject(UPaperFlipbook::StaticClass(), NULL, TEXT(“PaperFlipbook’/Game/Flipbooks/Enemy_Flipbook.Enemy_Flipbook’”)));
Enemy->SetRelativeRotation(FRotator(180.0f, -180.0f, 90.0f));
[FONT=courier new]void AEnemy::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
GEngine->AddOnScreenDebugMessage(-1, 0.5f, FColor::Red, FString::Printf(TEXT(“Something overlapped with me the enemy!”)));
[FONT=courier new]Laser = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT(“Laser”));
Sprite = Cast<UPaperSprite>(StaticLoadObject(UPaperSprite::StaticClass(), NULL, TEXT(“PaperSprite’/Game/Sprites/Laser_Sprite.Laser_Sprite’”)));
Laser->SetRelativeRotation(FRotator(180.0f, -180.0f, 90.0f));
That’s it basically. When I run the game, the laser is on the same Z-position as the enemy and when it moves over the enemy, nothing happens.
I have also tried [FONT=courier new]SetCollisionEnabled() in various ways on the enemy component, but it makes no difference.
Am I missing some setting somewhere? This is my first attempt at collision so there could be something I have overlooked.
The enemy sprites are Shrink Wrapped and the laser sprite is set to Tight Bounding Box and all are set to OverlapAll in the editor.
NOTE: I also have OnComponentHit set up but it does not fire either.