x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: Not Selected
Tags:
more ▼

asked Apr 30 '15 at 12:22 AM in C++ Programming

avatar image

IDON_EAT_DOGS
99 14 15 23

avatar image Napoleonite May 22 '16 at 10:14 AM

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.

https://answers.unrealengine.com/questions/407622/collision-component-must-be-placed-in-root.html

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

2) 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"));
     }
 }

3) Declare Proximity spheres for your collisions in your Actor:

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

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

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

5) 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!

more ▼

answered May 01 '15 at 12:43 PM

avatar image

Artem Gergel'
250 19 3 20

avatar image IDON_EAT_DOGS May 07 '15 at 02:51 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question