# Function replication not working

**URL:** <https://forums.unrealengine.com/t/function-replication-not-working/409415>\
**Category:** Multiplayer & Networking\
**Tags:** Networking, Replication, Server, unreal-engine, implementation, function, question\
**Created:** [November 12, 2017, 3:12pm UTC](https://forums.unrealengine.com/t/function-replication-not-working/409415 "2017-11-12T15:12:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_04e6fffe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_04e6fffe](https://forums.unrealengine.com/u/anonymous_user_04e6fffe)\
**Post date:** [November 12, 2017, 3:12pm UTC](https://forums.unrealengine.com/t/function-replication-not-working/409415/1 "2017-11-12T15:12:50Z")

</div>

I have recently started adding multiplayer to my project and looked at different guides on replication, variables work well so far i think. Now I started testing implementing functions and they don’t seem to work no matter what guide I use.

## AEntity.h

UFUNCTION(Server, Reliable, WithValidation)  
void ServerAttack();

##AEntity.cpp##

void AEntity::ServerAttack\_Implementation(){  
if(!Attacking){  
Attacking = true;  
}  
}

bool AEntity::ServerAttack\_Validate(){  
return true;  
}

ServerAttack\_Validate function doesn’t throw any errors while ServerAttack\_Implementation keeps throwing errors that it is not a member of AEntity. It throws an error to GENERATED\_BODY() saying class “AEntity” has no member “ServerAttack\_Implementation”

I have “UnrealNetwork.h” included in the cpp file

---

<div class="post-metadata">

**Author:** ![jjwisniewka](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jjwisniewka](https://forums.unrealengine.com/u/jjwisniewka)\
**Post date:** [January 29, 2018, 11:29am UTC](https://forums.unrealengine.com/t/function-replication-not-working/409415/2 "2018-01-29T11:29:50Z")

</div>

I have the same problem - have you managed to solve it?

---

<div class="post-metadata">

**Author:** ![Sevenplex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sevenplex](https://forums.unrealengine.com/u/Sevenplex)\
**Post date:** [January 30, 2018, 6:16am UTC](https://forums.unrealengine.com/t/function-replication-not-working/409415/3 "2018-01-30T06:16:22Z")

</div>

Change AEntity.h

UFUNCTION(Server, Reliable, WithValidation)  
void ServerAttack();  
virtual void ServerAttack\_Implementation();  
virtual bool ServerAttack\_Validate();

---

<div class="post-metadata">

**Author:** ![jjwisniewka](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jjwisniewka](https://forums.unrealengine.com/u/jjwisniewka)\
**Post date:** [January 30, 2018, 7:19am UTC](https://forums.unrealengine.com/t/function-replication-not-working/409415/4 "2018-01-30T07:19:53Z")

</div>

But still If I want to replicate to all platers in SerwerAttack I have to call Multicast function right? (at lest this is the only thing that’s working for me)

---

<div class="post-metadata">

**Author:** ![Sevenplex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sevenplex](https://forums.unrealengine.com/u/Sevenplex)\
**Post date:** [January 30, 2018, 7:37am UTC](https://forums.unrealengine.com/t/function-replication-not-working/409415/5 "2018-01-30T07:37:41Z")

</div>

As of UE 4.15 the compile system adds the implementation and validation definitions for you. Making the code for the header as follows:

```
AEntity.h

void Attack();

UFUNCTION(reliable, server, WithValidation)
void ServerAttack();

AEntity.cpp

void AEntity::Attack()
{
    // If this next check succeeds, we are *not* the authority, meaning we are a network client.
    if (Role < ROLE_Authority)
    {
        ServerAttack();
    }
}
 
bool AEntity::ServerAttack_Validate(l)
{
    return true;
}
 
void AEntity::ServerAttack_Implementation()
{
    // This function is only called on the server (where Role == ROLE_Authority), called over the network by clients.
    // Inside that function, Role == ROLE_Authority, so it won't try to call Attack() again.
    Attack();
}
```

---

<div class="post-metadata">

**Author:** ![KyoKazehaya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kyokazehaya/32/1145420_2.png) [@KyoKazehaya](https://forums.unrealengine.com/u/KyoKazehaya)\
**Post date:** [July 31, 2018, 1:15pm UTC](https://forums.unrealengine.com/t/function-replication-not-working/409415/6 "2018-07-31T13:15:18Z")

</div>

For anyone who is still looking for a solution to this problem it solved for me changing the macro GENERATED\_BODY() by GENERATED\_UCLASS\_BODY() then it will recognize the \_Implementation and \_Validate functions in the .cpp without creating the virtual declarations in the .h.

Also note when you change the macro you will need to add “const FObjectInitializer& ObjectIntializer” parameter to your class constructor ONLY in the cpp file.

Hope it helps!
