Can I FORCEINLINE a replicated function?

Hello.

Is it possible to do FORCEINLINE with a replicated function?
It would really save some space in my .cpp file.

In order for a function to be replicated, it needs to be a UFunction, and in order to be a UFunction, it must not be FORCEINLINE or FORCENOINLINE and a couple of other things

No.

Try using macros or a non-UFunction library

FORCEINLINE is a performance optimization and will increase the size of any translation unit you add it to.

RPC function must be UFUNCTION, but we don’t need define exactly same function, but we implement _Implementation and _Validate instead, which we can make FORCEINLINE. Next code works for me just fine:

/** Server RPC function */
UFUNCTION(Server, Reliable, WithValidation, BlueprintCallable, Category = "Category")
virtual void ServerCallString(const FString& string);

FORCEINLINE void ServerCallString_Implementation(const FString& string) { ... }
FORCEINLINE bool ServerCallString_Validate(const FString& string) { return true; }

Hth

That is actually pretty helpful, thanks!

Inline and force inline should cause you build errors as the UClass should fail to be referenced externally. You can have a ufunction that calls the forced inline version

i have forceinline ufunctions in my code, which work fine inside C++. (a problem calling them in BP, but they still compile and work. why do you think a ufunction can’t be forceinline?)

they don’t cause build errors however and the next code compiles perfectly:

FORCEINLINE UFUNCTION(BlueprintCallable)  
	void setIsAiming(bool new_val)		{setReplicatedFlagAt(1,new_val);}

I just had to remove inlined ufunctions from a plugin in 4.20 so this might not work going forward

technically it should be possible to have an inline ufunction though, because even if BP don’t know the concept of inline (as it is a interpreted language), ufunctions are still usable in C++ as well, and it doesn’t make much sense to uninline a function just to make it supported in BP, am i wrong?