5

I seem to be misunderstanding how to implement overlap events on my components. I've created a USphereComponent to follow my character. It's designed to fire overlap events on other nearby Actors that are within the player's reach:

AScrollsCharacter::AScrollsCharacter()
{
    ...Redacted irellevant code...

    //Create activate trigger radius
    USphereComponent* activateRadius = CreateDefaultSubobject<USphereComponent>(TEXT("Activate Radius"));
    activateRadius->InitSphereRadius(ACTIVATE_RADIUS);
    activateRadius->bGenerateOverlapEvents = true;
    activateRadius->SetupAttachment(RootComponent);
    activateRadius->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap);
    activateRadius->OnComponentBeginOverlap.AddDynamic(this, &AScrollsCharacter::OnOverlapActivateSphere);
    activateRadius->bHiddenInGame = false;
}

void AScrollsCharacter::OnOverlapActivateSphere(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
    GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("We got a collision."));
}

The sphere component attaches without error, and is the radius is drawn on screen at the correct size. However, when I bring the radius towards other actors in game and cause them to overlap, the event doesn't appear to be firing.

All actors involved have the the Generate Overlap Events flag set to true.

Can someone help me understand what I'm missing in this setup?

Edit: The debug bounds of the sphere component are colored orange while in the editor, but turn red when the game is running. Is that color change meaningful?

Nathan Wiles
  • 398
  • 4
  • 22

2 Answers2

1

If you're still trying to fix this problem, maybe try using

activateRadius->SetSphereRadius(ACTIVATE_RADIUS);

instead of

activateRadius->InitSphereRadius(ACTIVATE_RADIUS);

According to the docs, the function you're using, InitSphereRadius:

Sets the sphere radius without triggering a render or physics update.

I'm pretty sure you want that physics update.

jeevcat
  • 363
  • 2
  • 12
  • Thanks for the response! Unfortunately that doesn't seem to change anything. I think that SetSphereRadius triggers a forced render update, but without that forced update, one will occur each tick as normal anyway. – Nathan Wiles Sep 28 '16 at 04:35
0

Make sure that the other actors involved have their collision enabled too, and also make sure they actually have a colliding component. For example, if the other actors have skeletal mesh components, that mesh needs to have a physics asset or it won't have anything to collide with! You can also add a collision sphere/box/capsule to your other actors and make sure collision is enabled on that!

Bas in het Veld
  • 1,130
  • 9
  • 16
  • They are and they do. I stated in the post that all actors involve have the Generate Overlap Events flag set to true, implying that they all have colliding components. – Nathan Wiles Sep 16 '16 at 03:04