How to use UFUNCTION macro with inline methods?

I have the following method in my game mode class (header file):


void BadBugDied(APawn* BadBug) { BadBugs.Remove(BadBug); }

This compiles and works fine.
Now I add the UFUNCTION macro, to call this method from BP:



UFUNCTION(BlueprintCallable, Category = "Bad Bugs")
FORCEINLINE void BadBugDied(APawn* BadBug) { BadBugs.Remove(BadBug); }

This leads to the following error during compilation:

“Unrecognized type ‘void’ - type must be a UCLASS, USTRUCT or UENUM”

The same error occurs also when I use the inline keyword instead of the FORCEINLINE macro.

Am I missing something here?

My game mode class starts like this:


UCLASS(minimalapi)
class AGDemoGameMode : public AGameMode
{
	GENERATED_BODY()

Have you tried moving the implementation to the .cpp file or to the end of the header?

HTH

Sure, that would work.
But my intention was to compile this method inline …

Why do you want it to be inlined?

I would suggest getting the function to show up in BP before (trying) to get it inlined.

HTH

Well, whether or not a function or method in C++ should or should not be inlined is a broad topic, which I don’t want to discuss here. My question was more if it is possible in UE4 to have an inlined UFUNCTION :slight_smile:

It’s probably just a limitation of UHT (it has many).

It’s completely unnecessary though, inline or not is totally insignificant in comparison to the overhead of calling a function from blueprint. If you need to call this function from C++ a lot, then make an inline function to do the work, and then a separate BlueprintCallable UFUNCTION that just calls the inline function.

If you’re going to be calling the function so often from blueprint that you’re worrying about inlining it though, then you just shouldn’t be calling it from blueprint in the first place.

2 Likes

Seems to be a wise summary, thanks a lot!

for BlueprintNativeEvents use this syntax:

Code:

   UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "local") FORCEINLINE

USoundCue* getEmptyChamberSound();
USoundCue* getEmptyChamberSound_Implementation(){return nullptr;};

:slight_smile: thank me later

is it possible to create a #define macro to create blueprint callable functions?

Definitely possible yeah.

It may be a bug, but the solution is simple. Just remove the ‘inline’, and write the definition to the header. All definitions in a header will be treated as inline function.
class UAxx
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable)
void Hello(){printf(“xxx”);};
}

2 Likes

I’ve also been putting it at the end of the header file. But I always questioned whether or not it’s truly inlined if it’s a UFUNCTION. The compiler can still decide something isn’t inline if it can’t be. And maybe UFUNCTION can’t be inline.

class UAxx
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable)
void Hello();
}

FORCEINLINE_DEBUGGABLE void UAxx::Hello(){printf(“xxx”);};

You can try to use it this way:



FORCEINLINE void SomeFunction() {  };
UFUNCTION() void SomeFunction_implementation(); // cpp realisation


2 Likes