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"

"AddDynamic" not working

Hi All users. I Have a New Actor in "Unreal Engine 4.5.1" But This Actor Not Working.

Header File TriggerTest.h // Fill out your copyright notice in the Description page of Project Settings.

 #pragma once
 
 #include "GameFramework/Actor.h"
 #include "TriggerTest.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class ARMITA_API ATriggerTest : public AActor
 {
     GENERATED_UCLASS_BODY()
 
     TSubobjectPtr<UBoxComponent>Box;
     TSubobjectPtr<UPointLightComponent>Light;
 
     UFUNCTION()
         void Debug(FString Massage);
     UFUNCTION()
         void OnBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool FromSweep, const FHitResult& SweepResult);
     UFUNCTION()
         void OnEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool FromSweep, const FHitResult& SweepResult);
 };
 

C++ File TriggerTest.cpp

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "Armita.h"
 #include "TriggerTest.h"
 
 
 ATriggerTest::ATriggerTest(const class FPostConstructInitializeProperties& PCIP)
 : Super(PCIP)
 {
     Box = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Box"));
     Light = PCIP.CreateDefaultSubobject<UPointLightComponent>(this, TEXT("Light"));
     Box->bGenerateOverlapEvents = true;
     Box->SetRelativeScale3D(FVector(2,2,5));
     RootComponent = Box;
     Light->Intensity = 1000;
     Light->SetLightColor(FColor::Red);
     Light->AttachParent = RootComponent;
     Box->OnComponentBeginOverlap.AddDynamic(this, &ATriggerTest::OnBeginOverlap);
     Box->OnComponentEndOverlap.AddDynamic(this, &ATriggerTest::OnEndOverlap);
 }
 void ATriggerTest::OnBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool FromSweep, const FHitResult& SweepResult)
     {
 
         Light->SetLightColor(FColor::Green);
         Debug("Open");
     }
 void ATriggerTest::OnEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool FromSweep, const FHitResult& SweepResult)
     {
 
         Light->SetLightColor(FColor::Red);
         Debug("Close");
 
     }
     void ATriggerTest::Debug(FString Massage)
     {
         /*if (UEngine)
         {
             UEngine::AddOnScreenDebugMassage(-1, 1, FColor::Red, Massage);
 
 
         }*/
 
     }
 
 
 
 Unreal Engine 4.5.1 ERROR

alt text

Product Version: Not Selected
Tags:
untitled.jpg (104.0 kB)
more ▼

asked Nov 18 '14 at 08:09 AM in C++ Programming

avatar image

Ali1ty
41 3 6 22

avatar image Rama Nov 18 '14 at 10:12 AM

I had no issue getting begin overlap to fire off in 4.4, however I can confirm that I've had trouble getting begin overlap to fire via dynamic binding in 4.5, and yes I made sure the binding function was UFUNCTION(), and I also tried putting add dynamic later on, post init or begin play, but I still could not get it to activate for two collision channels that were set to overlap with each other very specifically.

I was testing in a character class to detect overlaps with static mesh actor deriving powerups.

I was adding the binding to the static mesh actor deriving class to detect if a player had collided with itself.

This definitely merits further investigation!

If no answers come forth for a while I can make a repro case.

Rama

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

2 answers: sort voted first

ok . my problem was Solved.

Header File :

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #pragma once
 
 #include "GameFramework/Actor.h"
 #include "TriggerTest.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class ARMITA_API ATriggerTest : public AActor
 {
     GENERATED_UCLASS_BODY()
 
     TSubobjectPtr<UBoxComponent>Box;
     TSubobjectPtr<UPointLightComponent>Light;
 
     UFUNCTION()
         void Debug(FString Massage);
     UFUNCTION()
         void OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool FromSweep, const FHitResult& SweepResult);
     UFUNCTION()
         void OnEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
 };
 

Cpp File :

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "Armita.h"
 #include "TriggerTest.h"
 
 
 ATriggerTest::ATriggerTest(const class FPostConstructInitializeProperties& PCIP)
 : Super(PCIP)
 {
     Box = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Box"));
     Light = PCIP.CreateDefaultSubobject<UPointLightComponent>(this, TEXT("Light"));
     Box->bGenerateOverlapEvents = true;
     Box->SetRelativeScale3D(FVector(2,2,5));
     RootComponent = Box;
     Light->Intensity = 10000;
     Light->SetLightColor(FColor::Red);
     Light->AttachParent = RootComponent;
     Box->OnComponentBeginOverlap.AddDynamic(this, &ATriggerTest::OnOverlap);
     Box->OnComponentEndOverlap.AddDynamic(this, &ATriggerTest::OnEndOverlap);
 }
 void ATriggerTest::OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool FromSweep, const FHitResult& SweepResult)
     {
 
         Light->SetLightColor(FColor::Green);
         Debug("Open");
     }
 void ATriggerTest::OnEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
     {
 
         Light->SetLightColor(FColor::Red);
         Debug("Close");
 
     }
     void ATriggerTest::Debug(FString Massage)
     {
         /*if (UEngine)
         {
             UEngine::AddOnScreenDebugMassage(-1, 1, FColor::Red, Massage);
 
 
         }*/
 
     }
 
 
 
 

Thanks To all.

more ▼

answered Nov 18 '14 at 10:28 AM

avatar image

Ali1ty
41 3 6 22

avatar image Sentientv2 Mar 21 '17 at 05:08 AM

Just came across this issue in my own learning. Wanted to add/second that the UFUNCTION was integral for my AddDynamic call to work.

avatar image toxicg0d May 14 '17 at 10:57 AM

To anyone seeing this recently: Adding UFUNCTION() will make your dynamic events work.

avatar image Craimasjien Mar 08 '18 at 08:44 PM

It also appears that you need to add the callback in your BeginPlay() method too (4.18.3). If added in the constructor for your AActor subclass it doesn't seem to work.

avatar image geoldery Jul 03 '18 at 02:50 PM

Thanks, this works fine!!!

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

I just had the same issue and as Craimasjien said: you better need add the AddDynamic(...) line in BeginPlay(). Thats why: if you have an existing Character Blueprint and decide to Add some OverlapEventhandling functionality to it, UE4 doesn´t register this call in the Constructor (but if you FIRST use AddDynamic in the constructor and THEN make the Character_BP out of it it works). Really annoying because the compiler does no error printing and you search for hours to find the bug.

more ▼

answered May 28 '18 at 05:27 AM

avatar image

Seim2k
51 3 6

avatar image KarakTheMad Dec 19 '18 at 09:13 PM

Thanks SO much for posting this. I've also been searching for hours for a solution. I'm using 4.21 and could not get AddDynamic(,,,) to fire either. Adding the statement to BeginPlay() did the trick.

(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