Only root component's collision is being detected

I have a box component as root collision, and it’s working. But now I want to add a trigger box to this actor and the trigger box’s onBeginOverlap function is not being triggered. Seems like only the component’s collision is being detected.

How do I make component’s collision work?

Hello,

To make the component collision work, you can do the following:

  1. Declare the Prox() function in your Actor:

    UFUNCTION(BlueprintNativeEvent, Category = “Collision”)
    //for blueprint implementation of the function
    void Prox(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);

//for native C++ implementation

virtual void Prox_Implementation(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
  1. Implement it :

    void AActorWithComponents::Prox_Implementation(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
    {
    //test functionality
    if (GEngine)
    {
    GEngine->AddOnScreenDebugMessage(0, 10.0f, FColor::White, TEXT(“Begin Overlap”));
    }
    }

  2. Declare Proximity spheres for your collisions in your Actor:

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
    UBoxComponent* FirstBoxTrigger;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
    UBoxComponent* SecondBoxTrigger;

  3. In Actor’s constructor, initialize the components, attach them to root and bind the Prox() method:

    FirstBoxTrigger = ObjectInitializer.CreateDefaultSubobject (this, TEXT(“First Box Trigger”));
    FirstBoxTrigger->AttachTo(RootComponent);
    FirstBoxTrigger->OnComponentBeginOverlap.AddDynamic(this, &AActorWithComponents::Prox);
    SecondBoxTrigger = ObjectInitializer.CreateDefaultSubobject (this, TEXT(“Second Box Trigger”));
    SecondBoxTrigger->AttachTo(RootComponent);
    SecondBoxTrigger->OnComponentBeginOverlap.AddDynamic(this, &AActorWithComponents::Prox);

  4. Place your Actor in the level. Select Box components in Details tab and place them according to your needs.
    This should do it. Also please don’t forget to check collision settings for the Boxes (especially Generate Overlap Events flag).
    Hope this helped!
    Cheers!

thanks you, it works.

but I got this warning, which I am a little bit concerned. Should I ignore it?

Warning 3 warning C4996: Function PortalTile::OnBlueEndTriggerOverlap_Implementation needs native implementation by virtual void OnBlueEndTriggerOverlap_Implementation(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) due to its properties. Currently OnBlueEndTriggerOverlap_Implementation declaration is autogenerated by UHT. Since next release you’ll have to provide declaration on your own. Please update your code before upgrading to the next release, otherwise your project will no longer compile. d:\projecttap\source\projecttap\tiles\PortalTile.h(14)(

Actually the non-root-component collision detection does work but only for collision with pawns. Because of this weird behavior I assumed that it was an UE4-bug (and I still do not know why the UE4 devs designed it like this). Took me a while to figure it out.

Glad there is finally a post with a c++ workaround though. Especially for cases where you use inheritance and need different collision-shapes depending on the child-blueprint.

1 Like