Illegal call of non-static member function (Help - I now NOTHING!)

Hi,

(Can’t believe I typo’d ‘know’ in the thread title - now I look like a total 10 year old)

I’m trying to get kerning pairs for a text thing i’m working on. i’m pretty bad at c++, I think i’m nearly there but any help with my Illegal call of non-static member function error would be really handy (I know next to nothing about c++ and i’m brute forcing my way through it.

I haven’t fully populated the blueprint node with all of the inputs, but I figure when I can actually get ‘GetKerning’ to work I can fiddle with that.

I think i’ve managed to get the first character of each FString as a TCHAR (about 2 hours of keyboard mashing)

Here’s the .h



UFUNCTION(BlueprintPure, Category = "DansWonkyPlugins")
static int32 GetKerningData(FString LChar, FString RChar, FFontData InFontData);

and here’s the .cpp



int32 UMyBlueprintFunctionLibrary::GetKerningData(FString LChar, FString RChar, FFontData InFontData)
{

	int32 InSize = 100;
	const int32 Scale = 100;
	const TCHAR* First = *LChar;
	const TCHAR* Second = *RChar;
	return FSlateFontCache::GetKerning(InFontData, InSize, First[0], Second[0], Scale);
}

(I’ve added the slate and slatecore to the build file - the non-static error is the only one right now)

Help me C++ Kenobi, you’re my only hope.

A “static” function in a class runs without any particular instance of a class. There is no “this” and there is no particular object instance.

A non-static function in a class requires an actual object instance, and has a “this” inside it.

When you declare your function “static” it says “this doesn’t need an object instance.”

But, from within that static function, you cannot call object functions that aren’t static, because they need a “this” – the actual object they operate on.

Now, when asking for help with errors, you need to ALWAYS COPY AND PASTE THE EXACT ERROR TEXT. And put it inside code tags in the forum, to make it easy to use.

I’m going to make a guess here, and believe that it complains about the call to “FSlateFontCache::GetKerning”
The reason, in that case, would be that FSlateFontCache::GetKerning() is not static, and thus needs a particular instance of a FSlateFontCache to work on.
Assuming you have one such instance, you would call it with “.” or “->” notation:



    pTheFontCache->GetKerning( ... )


Hi jwatte,

Thanks for the input. I’m starting to understand that hacking my way into c++ is not a great idea. I understand now that you access the GetKerning() function through a reference or instance which i’ve tried to supply through the blueprint interface, but it’s throwing an OtherCompilationError(5) if I try either. This might be a pointer issue.

Looking at the API I think I may be going about it the wrong way. The FSlateFontMeasure class looks to be more encompassing than getting it via FSlateFontCache as along with kerning pairs I can do some other measurements too. I’m going to have a fiddle. This class has a Create static function - do I need to use this or can I just pass in a reference to a font i’ve made in the editor?

Thanks for the help. I’ve often hit a wall when I find a really neat function in the API but just can’t get it to work. I wish there was actual code on the API pages. Saying that, I know the clouds will part for me with the c++ soon and i’ll get it - it’s just a syntax thing I think, with the ::'s and ->'s and stuff like that. I can make python do whatever I need.