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. 

AddDynamic Problem

I can't manage to use AddDynamic in my constructor. It does not appear in the list and when i compile it, it says i need to define it and i get many errors. What is this about? Am i wrong to use it in the constructor? Do i need to define it in some way?

I get this error: Errore C2664 'void TBaseDynamicMulticastDelegate ,AActor ,UPrimitiveComponent ,int32,bool,const FHitResult &>::__Internal_AddDynamic(UserClass ,void (__cdecl ANPC:: )(UPrimitiveComponent ,AActor ,UPrimitiveComponent ,int32,bool,const FHitResult &),FName)': cannot convert argument 2 from 'void (__cdecl ANPC:: )(AActor ,int32,bool,const FHitResult &)' to 'void (__cdecl ANPC:: )(UPrimitiveComponent ,AActor ,UPrimitiveComponent ,int32,bool,const FHitResult &)' GoldenEgg D:\Matteo\Progetti UE4\GoldenEgg 4.16\Source\GoldenEgg\NPC.cpp 18

Product Version: UE 4.16
Tags:
more ▼

asked Jun 05 '17 at 09:04 PM in C++ Programming

avatar image

unreal_error
11 2 3 3

avatar image Vawx Jun 06 '17 at 03:23 AM

Looks like it is expecting a UPrimitiveComponent but you are trying to use a AActor.

Can you paste what is in your constructor?

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

3 answers: sort voted first

I think it was "ProxSphereOverlap" or something like this. However i changed it many times and only with the name "BeginOverlap" it works. As i said if i change just the name of the function leaving the definition correct, it seems to not work anymore.

more ▼

answered Jun 06 '17 at 12:54 PM

avatar image

unreal_error
11 2 3 3

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

The syntax for AddDynamic is as follows

 OnComponentOverlap.AddDynamic(this, &ANPC::OnOverlapThing);

It looks like your issue is with the function that you are binding the delegate to. It is expecting the following function definition

 void OnOverlapThing(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);

Hopefully this helps!

more ▼

answered Jun 06 '17 at 04:28 AM

avatar image

HailstoneJosh
226 5 3 14

avatar image unreal_error Jun 06 '17 at 06:12 AM

I actually find it working when i renamed the function into "BeginOverlap". I am kinda new to ue4 but it think this is silly since the funcion is not a primitive function of any base class (i guess) . So if i let the definition correct and refactor the name, it doesn't work anymore. Why is that? Can't i just call the function as i want?

avatar image HailstoneJosh Jun 06 '17 at 12:30 PM

What did you have the function named before?

avatar image unreal_error Jun 06 '17 at 12:55 PM

I think it was "ProxSphereOverlap" or something like this. However i changed it many times and only with the name "BeginOverlap" it works. As i said if i change just the name of the function leaving the definition correct, it seems not to work anymore.

avatar image HailstoneJosh Jun 06 '17 at 01:22 PM

That's strange, maybe if you post your code it would help to figure out what the issue is.

Have you also tried deleting your Intermediate & Saved folders and building again?

avatar image unreal_error Jun 06 '17 at 04:02 PM

Declaration: UFUNCTION() void BeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);

Definition: **void ANPC::BeginOverlap(UPrimitiveComponent OverlappedComponent, AActor OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult) { GEngine->AddOnScreenDebugMessage(-1, 2, FColor::White, npcMessage); }

Binding: proxSphere->OnComponentBeginOverlap.AddDynamic(this, &ANPC::BeginOverlap);

I am new to UE4, how do i delete those files you talk about? PS: i posted only these lines of code cause the whole code required too many characters and i couldn't post it.

Thanks for helping ! :)

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

I know this is old, but the issue is still valid.

Closing down UE4 and launching it again seems to fix the problem. I'm guessing its a caching issue. Annoying, but great to have found a consistent solution.

Edit: issue still valid as of 4.19.2

more ▼

answered Aug 29 '18 at 06:54 PM

avatar image

SupaHam
1 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