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"

OnComponentBeginOverlap works but not OnComponentEndOverlap

Aside from the code, here's a list of things I've tried out that still don't work:

  • Changing from AddUniqueDynamic to AddDynamic

  • Changing from OnComponentEndOverlap to OnActorEndOverlap

  • Changing both OnComponentBeginOverlap and OnComponentEndOverlap from protected to private

Below is my code. Any help is appreciated.

LevelStreamingTrigger.cpp:

 ALevelStreamingTrigger::ALevelStreamingTrigger()
 {
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
     OverlapVolume = CreateDefaultSubobject<UBoxComponent>(TEXT("OverlapVolume"));
     OverlapVolume->bGenerateOverlapEvents = true;
     RootComponent = OverlapVolume;
 
     OverlapVolume->OnComponentBeginOverlap.AddUniqueDynamic(this, &ALevelStreamingTrigger::OverlapBegins);
     OverlapVolume->OnComponentEndOverlap.AddUniqueDynamic(this, &ALevelStreamingTrigger::OverlapEnds);
 }
 
 
 void ALevelStreamingTrigger::OverlapBegins(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
 {
     if (OtherActor->IsA(ACharacter::StaticClass()))
     {
         ACharacter* MyCharacter = UGameplayStatics::GetPlayerCharacter(this, 0);
         if (OtherActor == MyCharacter && LevelToLoad != "")
         {
             FLatentActionInfo LatentInfo;
             UGameplayStatics::LoadStreamLevel(this, LevelToLoad, true, true, LatentInfo);
         }
     }
     
 }
 
 void ALevelStreamingTrigger::OverlapEnds(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
 {
     if (OtherActor->IsA(ACharacter::StaticClass()))
     {
         ACharacter* MyCharacter = UGameplayStatics::GetPlayerCharacter(this, 0);
         if (OtherActor == MyCharacter && LevelToLoad != "")
         {
             FLatentActionInfo LatentInfo;
             UGameplayStatics::UnloadStreamLevel(this, LevelToLoad, LatentInfo);
         }
     }
 }

LevelStreamingTrigger.h:

 UCLASS()
 class PROCEDURALGENERATOR_API ALevelStreamingTrigger : public AActor
 {
     GENERATED_BODY()
     
 public:    
     // Sets default values for this actor's properties
     ALevelStreamingTrigger();
 
 protected:
     UPROPERTY(EditAnywhere)
         FName LevelToLoad;
 
 private:
     // Overlap volume to trigger level streaming
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
         UBoxComponent* OverlapVolume;
 
     UFUNCTION()
         void OverlapBegins(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
 
     UFUNCTION()
         void OverlapEnds(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
 };
Product Version: UE 4.19
Tags:
more ▼

asked Jul 15 '18 at 02:59 AM in C++ Programming

avatar image

Paul_LTC
30 3 3 10

avatar image DarkwindRichard Jul 16 '18 at 06:57 PM

Are you using a blueprint that inherits from ALevelStreamingTrigger? If so, did you create these event handlers before or after creating the blueprint? Does your OverlapVolume have a collision profile that supports overlapping? Are you using hot reload?

On a side note, please bump your own threads instead of bumping a thread that is almost nine months old.

avatar image Paul_LTC Jul 17 '18 at 10:20 AM

Yes to all the questions you've asked. Thanks for contributing to help!

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

1 answer: sort voted first

Fixed it! For some reason, the LevelStreamingTrigger instance doesn't update accordingly to the code. Therefore, I put the AddDynamic from the constructor to BeginPlay. For anyone of you who's stuck with this problem, you may also follow this guide right here: https://answers.unrealengine.com/questions/673324/c-code-doesnt-update-unless-instance-gets-replaced.html

more ▼

answered Jul 17 '18 at 10:17 AM

avatar image

Paul_LTC
30 3 3 10

avatar image DarkwindRichard Jul 17 '18 at 02:08 PM

This is because you added the listeners after creating the blueprint of the type and are using hot reload. A practice I've come to use is to always close the editor whenever I'm going to make a change to code, make the change, then relaunch the editor from Visual Studio (Debug -> Start without debugging). It's annoying at first, but I've never run into this kind of problem since.

(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