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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Begin overlap not working but end overlap is!?

Working on a simple inventory system where the player picks up items as they collide with them.

For the life of me I can't get my OnComponentBeginOverlap delegate to be called. But my OnComponentEndOverlap delegate does get called. Does this make any sense?

Both the character and the item itself are set to bGenerateOverlapEvents = true.

relevant Item.h:

 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Item)
 UShapeComponent *CollisionShape;
  
 
 UFUNCTION()
     void BeginCollision(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
 
 UFUNCTION()
     void EndCollision(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);


relevant Item.cpp: (In constructor)

 CollisionShape = CreateDefaultSubobject<UBoxComponent>(TEXT("CollisionShape"));
 CollisionShape->bGenerateOverlapEvents = true;
 RootComponent = CollisionShape;
     
 CollisionShape->OnComponentBeginOverlap.AddDynamic(this, &AItem::BeginCollision);
 CollisionShape->OnComponentEndOverlap.AddDynamic(this, &AItem::EndCollision);

Delegate functions:

 void AItem::BeginCollision(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
 {
         UE_LOG(LogTemp, Warning, TEXT("player collided with item"));
         GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Green, FString("PlayerCollided with item"));
         Destroy();
     
 }
 
 void AItem::EndCollision(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex)
 {
     UE_LOG(LogTemp, Warning, TEXT("collision ended"));
     GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Green, FString("collision ended"));
 }




Product Version: UE 4.12
Tags:
more ▼

asked Jul 09 '16 at 03:49 AM in C++ Programming

avatar image

Martamius
6 2 2

avatar image MJ_01 Jul 10 '16 at 04:16 PM

Does it call OnComponentBeginOverlap after it calls OnComponentEndOverlap? OnComponentBeginOverlap will not get called if the component is already overlapping when it spawns.

avatar image Martamius Jul 10 '16 at 08:46 PM

Begin overlap never gets called. I'll walk my character into the object and begin overlap does not get called. But when I walk the character out, end overlap is called. I assume this means that my collision rules are working as intended. But I can't for the life of me figure out why begin overlap isn't being called.

avatar image rantrod Jul 12 '16 at 09:52 PM

Parameters changed in 4.12. Can you try removing "OtherComp" from your BeginCollision and EndCollision? so for example,

 void BeginCollision(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

That's how I have it and it works for me.

avatar image Martamius Jul 12 '16 at 10:18 PM

Hmm. That isn't compiling. It looks like it wants the UPrimitiveComponent after the AActor. How do you know the parameters changed? The documentation I'm using is here: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UPrimitiveComponent/OnComponentBeginOverlap/index.html

Here's the compile error after making your change:

error C2664: 'void TBaseDynamicMulticastDelegate::__Internal_AddDynamic(UserClass ,void (__cdecl AMayhemItem:: )(UPrimitiveComponent ,AActor ,UPrimitiveComponent ,int32,bool,const FHitResult &),FName)': cannot convert argument 2 from 'void (__cdecl AMayhemItem:: )(UPrimitiveComponent ,AActor ,int32,bool,const FHitResult &)' to 'void (__cdecl AMayhemItem:: )(UPrimitiveComponent ,AActor ,UPrimitiveComponent ,int32,bool,const FHitResult &)'

Thanks for the help.

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

1 answer: sort voted first

I figured it out, kind of. I renamed my delegates and deleted and recreated the blueprint class that extends my item class and it now works. Not sure which step fixed it.

more ▼

answered Jul 13 '16 at 12:28 AM

avatar image

Martamius
6 2 2

(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