# Declaring a function with c++ macro

**URL:** <https://forums.unrealengine.com/t/declaring-a-function-with-c-macro/1251989>\
**Category:** Programming & Scripting\
**Tags:** Gameplay-Attributes, macro, unreal-engine, Gameplay-Ability-System, CPP, question\
**Created:** [August 5, 2023, 9:07pm UTC](https://forums.unrealengine.com/t/declaring-a-function-with-c-macro/1251989 "2023-08-05T21:07:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scorch621](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Scorch621](https://forums.unrealengine.com/u/Scorch621)\
**Post date:** [August 5, 2023, 9:07pm UTC](https://forums.unrealengine.com/t/declaring-a-function-with-c-macro/1251989/1 "2023-08-05T21:07:46Z")

</div>

I try to declare and define the replication function for GAS attributes with C++ macro.

Macro:

```auto
#define ATTRIBUTE_REPLICATE_FUNCTION(PropertyName) \
virtual void OnRep_##PropertyName##(const FGameplayAttributeData& OldValue) \
{ \
	GAMEPLAYATTRIBUTE_REPNOTIFY(UBaseAttributeSet, ##PropertyName##, OldValue) \
}

```

It works fine by itself. But when I add ReplicatedUsing specifier, the project does not compile.

Example:

```auto
UPROPERTY(BlueprintReadOnly, Category = "Attributes", ReplicatedUsing = OnRep_Health)
FGameplayAttributeData Health;
ATTRIBUTE_ACCESSORS(UBaseAttributeSet, Health);
ATTRIBUTE_REPLICATE_FUNCTION(Health);

```

compilation error:  
`Replication notification function 'OnRep_Health' not found`

I feel like that’s because UPROPERTY is parsed by the Unreal Header Tool before C++ compiler handles the macro

Is there a way to make it work?

---

<div class="post-metadata">

**Author:** ![GabUECV](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gabuecv/32/1194717_2.png) [@GabUECV](https://forums.unrealengine.com/u/GabUECV)\
**Post date:** [August 5, 2023, 10:11pm UTC](https://forums.unrealengine.com/t/declaring-a-function-with-c-macro/1251989/2 "2023-08-05T22:11:51Z")

</div>

> I feel like that’s because UPROPERTY is parsed by the Unreal Header Tool before C++ compiler handles the macro

That’s definitively possible. Maybe try to put the ATTRIBUTE\_REPLICATE\_FUNCTION and ATTRIBUTE\_ACCESSORS _before_ the UPROPERTY declaration, but I don’t think it will work…

---

<div class="post-metadata">

**Author:** ![Scorch621](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Scorch621](https://forums.unrealengine.com/u/Scorch621)\
**Post date:** [August 5, 2023, 10:51pm UTC](https://forums.unrealengine.com/t/declaring-a-function-with-c-macro/1251989/3 "2023-08-05T22:51:09Z")

</div>

No, it doesn’t work
