TArray FGetter::CreateUObject

Hey,

I’ve tried to use slate c++ with the following tutorial Tutorial: Custom GUI with Slate Styles | Unreal Engine 4 blog .
But somehow I get some errors using

ATBCharacter:

FORCEINLINE float ATBCharacter::GetHitPoints()
{
	return hit_points_;
}

Slate widget construct():

#include "SSHealthBar.h"
#include "TBCharacter.h"


BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SSHealthBar::Construct(const FArguments& InArgs)
{
	TAttribute<float> value = TAttribute<float>::Create(TAttribute<float>::FGetter::CreateUObject(this, &ATBCharacter::GetHitPoints));

	//ChildSlot
	//[
	//	//SNew()
	//];
	
}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION

none of the 2 overloads could convert all the argument types
1> with
1> [
1> ObjectType=float
1> ]
1> d:\programme\engines\ue4\epic games\4.7\engine\source\runtime\core\public\delegates\DelegateSignatureImpl_Variadics.inl(220): could be ‘TBaseDelegate TBaseDelegate::CreateUObject(UserClass ,float (__cdecl SSHealthBar:: )(void) const)’
1> with
1> [
1> ObjectType=float
1> , UserClass=SSHealthBar
1> ]
1> d:\programme\engines\ue4\epic games\4.7\engine\source\runtime\core\public\delegates\DelegateSignatureImpl_Variadics.inl(215): or ‘TBaseDelegate TBaseDelegate::CreateUObject(UserClass ,float (__cdecl SSHealthBar:: )(void))’
1> with
1> [
1> ObjectType=float
1> , UserClass=SSHealthBar
1> ]
1> while trying to match the argument list ‘(SSHealthBar const , float (__cdecl ATBCharacter:: )(void) const)’

header file

class TUTORIALBOX_API SSHealthBar : public SCompoundWidget
{
public:
	SLATE_BEGIN_ARGS(SSHealthBar)
	{}
	SLATE_END_ARGS()

	/** Constructs this widget with InArgs */
	void Construct(const FArguments& InArgs);
};

can anyone help?

Hi there!

GetHitPoints function should be const.

Cheers

Already tried this solution but it doesnt work. Still the Same error
,
,

Could you paste entire class here? It works on my end so there must be something wrong with your implementation.

Btw. return hit_points_;why do you have underscore (_) ending your variable name?

I will Provider more code as fast as possible. It’s the trailing underscore naming convention for member variables. I don’t the naming Rules from Epic

updated my initial post, btw, which version do you use? i’m using 4.7

dude… you’re in the SHealthBar class, using ‘this’ and expect it be treated as UObject

you need to pass pointer to your character class to a widget or create and bind your widget in character class.

Check out the tutorial once again and read carefully.

omg, now i can see my problem… stupid mistake. well thank you!