# How to use UFUNCTION macro with inline methods?

**URL:** <https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [July 16, 2016, 10:30pm UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168 "2016-07-16T22:30:40Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_f3fb80e6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f3fb80e6](https://forums.unrealengine.com/u/anonymous_user_f3fb80e6)\
**Post date:** [July 16, 2016, 10:30pm UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/1 "2016-07-16T22:30:40Z")

</div>

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

```auto

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

```

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

```auto

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?

---

<div class="post-metadata">

**Author:** ![ryan20fun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ryan20fun/32/1194363_2.png) [@ryan20fun](https://forums.unrealengine.com/u/ryan20fun)\
**Post date:** [July 17, 2016, 11:43am UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/2 "2016-07-17T11:43:40Z")

</div>

My game mode class starts like this:

```auto

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f3fb80e6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f3fb80e6](https://forums.unrealengine.com/u/anonymous_user_f3fb80e6)\
**Post date:** [July 17, 2016, 12:18pm UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/3 "2016-07-17T12:18:54Z")

</div>

> [@ryan20fun;566014](#):
>
> Have you tried moving the implementation to the .cpp file or to the end of the header?

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

---

<div class="post-metadata">

**Author:** ![ryan20fun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ryan20fun/32/1194363_2.png) [@ryan20fun](https://forums.unrealengine.com/u/ryan20fun)\
**Post date:** [July 17, 2016, 3:25pm UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/4 "2016-07-17T15:25:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f3fb80e6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f3fb80e6](https://forums.unrealengine.com/u/anonymous_user_f3fb80e6)\
**Post date:** [July 17, 2016, 7:39pm UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/5 "2016-07-17T19:39:39Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![kamrann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kamrann](https://forums.unrealengine.com/u/kamrann)\
**Post date:** [July 17, 2016, 9:25pm UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/6 "2016-07-17T21:25:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f3fb80e6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f3fb80e6](https://forums.unrealengine.com/u/anonymous_user_f3fb80e6)\
**Post date:** [July 17, 2016, 9:40pm UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/7 "2016-07-17T21:40:27Z")

</div>

> [@kamrann;566172](#):
>
> 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.

Seems to be a wise summary, thanks a lot!

---

<div class="post-metadata">

**Author:** ![Arty-McLabin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arty-mclabin/32/1012076_2.png) [@Arty-McLabin](https://forums.unrealengine.com/u/Arty-McLabin)\
**Post date:** [February 6, 2018, 1:25pm UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/8 "2018-02-06T13:25:46Z")

</div>

for BlueprintNativeEvents use this syntax:

Code:

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

```

USoundCue\* getEmptyChamberSound();  
USoundCue\* getEmptyChamberSound\_Implementation(){return nullptr;};

🙂 thank me later

---

<div class="post-metadata">

**Author:** ![falola](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@falola](https://forums.unrealengine.com/u/falola)\
**Post date:** [September 4, 2018, 7:54pm UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/9 "2018-09-04T19:54:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thovex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@thovex](https://forums.unrealengine.com/u/thovex)\
**Post date:** [November 5, 2018, 11:00am UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/10 "2018-11-05T11:00:05Z")

</div>

Definitely possible yeah.

---

<div class="post-metadata">

**Author:** ![Jack\_Myth](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jack\_Myth](https://forums.unrealengine.com/u/Jack_Myth)\
**Post date:** [December 21, 2018, 10:30am UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/11 "2018-12-21T10:30:17Z")

</div>

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”);};  
}

---

<div class="post-metadata">

**Author:** ![illYay](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@illYay](https://forums.unrealengine.com/u/illYay)\
**Post date:** [March 9, 2021, 1:36am UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/12 "2021-03-09T01:36:41Z")

</div>

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”);};

---

<div class="post-metadata">

**Author:** ![HorusWM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HorusWM](https://forums.unrealengine.com/u/HorusWM)\
**Post date:** [March 9, 2021, 8:22am UTC](https://forums.unrealengine.com/t/how-to-use-ufunction-macro-with-inline-methods/69168/13 "2021-03-09T08:22:25Z")

</div>

You can try to use it this way:

```auto

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

```
