Using Function Pointer as parameter raises error

Hey all!

So I am using a method which uses a Function Pointer as an input parameter.

This is how the declaration and definition look like:

.h

UFUNCTION()
		bool PerformTask(void (AItem::*FunctioPtr)(), uint8 Priority, float Length, bool bSuspendEqualPriority = false);

.cpp

 bool AItem::PerformTask(void (AItem::*FunctioPtr)(), uint8 Priority, float Length, bool bSuspendEqualPriority)
    {
    	//...
    }

This setup worked in a prior project, but now it raises a “Unrecognized type ‘void’” error.
Why is this happening and how could I resolve it?

Thanks!

#UFUNCTION() ?

Does your function have to be UFUNCTION()?

Does it compile if you dont use UFUNCTION() ?

Let us know!

Rama

Omitting the UFUNCTION() declaration did actually solve the problem!

Thanks Rama, also for your article about function pointers!

Greetings, guys. I’ve got similar question.
So is it possible somehow to use function pointers with UFUNCTION macro to call them from blueprints?

I don’t think that’s possible. However you could use the function name as a parameter (the function to call needs to be a UFUNCTION too) and then execute that function via ProcessEvent(FindFunction(FunctionName), NULL) on a UObject derived object.

Thanks, Fluppi, I think that it should work in my case. At least I will try :slight_smile:

I got this syntax compiling for function declaration, but not sure exactly how to call the function passed in as the parameter. Any ideas?

void APFCharacter::Exclaim(void (APFCharacter::*ExclaimFunc)(void))
{
	(this->*ExclaimFunc())();
}

Here’s the error:

12>C:\UnrealEngine\Prizefighter\Source\Prizefighter\Private\PFCharacter.cpp(719): error C2064: term does not evaluate to a function taking 0 arguments