Gameplay Ability System and C++

I am following a tutorial on Ability System on UDemy. The instructor is using is using UE4.20 I am using using UE 5.1 I know I should be using the same editor but I am not. When I compile my code I get an error message C2446: ‘==’ : no conversion from ‘T *’ to FProperty *’ with [ T=UProperty ] and this message note: Types pointed to are unrealted; conversion requires reinterpret_cast. C-style cast or parenthesized function-style cast. I just started my C++ and UE adventure in January and haven’t come across the get so I am stumped. I have also attached pictures of the code and error.

[type or paste code here](https://1drv.ms/i/s!AjmNDGN_deFZhPUbI5IeIcbde8CWbw?e=Diir63)
[type or paste code here](https://1drv.ms/i/s!AjmNDGN_deFZhPUaHQSxoCq0vmUcmQ?e=Rj8qJR)

Hello there Jeywun!

As the images you posted were only linked, I am posting the relevant one here for anyone else who has a similar issue to be able to get the context of your question later. (If ever the image link were to not work anymore)

I checked the Source code for the relevant functions / types you are using to understand the problem better.

	/** Returns raw property */
	FProperty* GetUProperty() const
	{
		return Attribute.Get();
	}

As you can see, this function returns a FProperty pointer.

On the other hand, the FindFieldChecked template function returns a T pointer (whatever type T maybe). In your case T is a UProperty type.

FindFieldChecked<UProperty>(UAttributeSetBase::StaticClass(), GET_MEMBER_NAME_CHECKED(UAttributeSetBase, Health));

Change the template type T to be a FProperty instead and everything should work. The type UProperty (NOT to be confused with the macro UPROPERTY(…)) was deprecated in favour of the type FProperty in one of the past Engine versions.

Like so:

FindFieldChecked<FProperty>(UAttributeSetBase::StaticClass(), GET_MEMBER_NAME_CHECKED(UAttributeSetBase, Health));

Hope this explanation helps!

Thank you, I was able to get a successful compile. Now I have to learn how to use the UE Manual more efficiently. I really appreciate your help.

1 Like

I just want to chime in and say the way its done here is not the recommended way, you are best to utilize the special macro’s that Epic have provided us. I will show an example here:

#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)

This goes in your header file of your attribute set, under your includes, before your class declaration.

To use them, you define your attribute as normal, but put this additional thing below it

	UPROPERTY(BlueprintReadOnly, Meta = (AllowPrivateAccess = true))
	FGameplayAttributeData Health;
        ATTRIBUTE_ACCESSORS(ThisClass, Health);

You can now use it like following in your functions in your attribute set

if (Data.EvaluatedData.Attribute == GetHealthAttribute())

Hope this helps.

2 Likes

Thank you, I will use this. I really appreciate your help.