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. 

How pass function to argument?(C++)

How pass func(from bp or not) in argument?

 DECLARE_DELEGATE(FuncName);
 UFUNCTION(BlueprintCallable)
 void SomeFuncToPass(FuncName& fn);

This not work. P.S Log: (2) Error: Unrecognized type 'FuncName' - type must be a UCLASS, USTRUCT or UENUM

Product Version: UE 4.15
Tags:
more ▼

asked Feb 27 '17 at 08:03 PM in C++ Programming

avatar image

Noortvel
10 3 7 11

avatar image Filippoml Feb 27 '17 at 08:51 PM

What does "This not work" means? Any errors, logs?

avatar image Noortvel Feb 28 '17 at 12:31 PM

(2) Error: Unrecognized type 'FuncName' - type must be a UCLASS, USTRUCT or UENUM

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

2 answers: sort voted first

It sounds like you've wrongly placed your delegate declaration. Delegates need to be declared after your includes, but before any class declaration, ie like this:

 #include "YourClass.generated.h"
 
 DECLARE_DYNAMIC_DELEGATE(FFuncName);
 
 UCLASS()
 class AClass : public AParentClass
 {
       GENERATED_BODY()
       //Rest of class...

Do you mind giving us the full code from the first line up until the GENERATED_BODY() of the class?

EDIT: I see you've updated your question. In your case, I believe you are looking to use DECLARE_DYNAMIC_DELEGATE, not DECLARE_DELEGATE. A blueprint cannot use a regular delegate to my knowledge, as it is not compatible with Unreal's reflection system as I've understood it.

more ▼

answered Feb 28 '17 at 01:53 PM

avatar image

Drunkenvalley
371 14 21 46

avatar image Noortvel Feb 28 '17 at 02:34 PM

This may be due to "UFUNCTION(BlueprintCallable)"? Just i tried so

 DECLARE_DELEGATE(FuncName);
 void TestFunc(FNameFunc f);

And it compile.

avatar image Drunkenvalley Feb 28 '17 at 02:35 PM

Yes. As mentioned, blueprints cannot use a "regular" delegate, hence you need to use the "DYNAMIC" keyword instead.

Try this.

  DECLARE_DYNAMIC_DELEGATE(FuncName);
  UFUNCTION(BlueprintCallable)
  void SomeFuncToPass(FuncName& fn);

avatar image Noortvel Feb 28 '17 at 05:30 PM

if

  DECLARE_DYNAMIC_DELEGATE(FNameFunc);
   UFUNCTION(BlueprintCallable)
   void SomeFuncToPass(FNameFunc fn);

then :

Error PyCharacter.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl APyCharacter::TestFunc(class FNameFunc)" (?TestFunc@APyCharacter@@QEAAXVFNameFunc@@@Z) referenced in function "public: void __cdecl APyCharacter::execTestFunc(struct FFrame &,void * const)" (?execTestFunc@APyrCharacter@@QEAAXAEAUFFrame@@QEAX@Z)

if :

      DECLARE_DYNAMIC_DELEGATE(FNameFunc);
       UFUNCTION(BlueprintCallable)
       void SomeFuncToPass(FNameFunc& fn);

then : (13) error C4239: nonstandard extension used: 'argument': conversion from 'FNameFunc' to 'FNameFunc &' (13): note: A non-const reference may only be bound to an lvalue (13) : error C4239: nonstandard extension used: 'argument': conversion from 'FNameFunc' to 'FNameFunc &' (13) : note: A non-const reference may only be bound to an lvalue

(13) string :

     GENERATED_BODY()
 
avatar image Drunkenvalley Mar 01 '17 at 11:11 AM

Drop the ampersand, ie from FNameFunc& to instead just FNameFunc?

avatar image Noortvel Mar 02 '17 at 05:47 PM

Just remember declare body

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

My experience using it in a function was like this:

 FunctionTakingDelegate(FNameOfDelegate Function)
 {
       if(Function.IsBound())
       {
             //Do stuff
       }
 }

Nothing fancy in this case. Probably ain't quite right, but I didn't think much of it since the delegate effectively only transfers access to the function anyway.

more ▼

answered Feb 27 '17 at 08:48 PM

avatar image

Drunkenvalley
371 14 21 46

(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