# Network programming - a lot of functions and code or something is wrong?

**URL:** <https://forums.unrealengine.com/t/network-programming-a-lot-of-functions-and-code-or-something-is-wrong/57950>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [March 11, 2016, 4:28pm UTC](https://forums.unrealengine.com/t/network-programming-a-lot-of-functions-and-code-or-something-is-wrong/57950 "2016-03-11T16:28:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Young\_Wolf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Young\_Wolf](https://forums.unrealengine.com/u/Young_Wolf)\
**Post date:** [March 11, 2016, 4:28pm UTC](https://forums.unrealengine.com/t/network-programming-a-lot-of-functions-and-code-or-something-is-wrong/57950/1 "2016-03-11T16:28:56Z")

</div>

Hello friends,

I’ve started working persistently on my project game and it seems that writing RPC functions creates a lot of extra code and functions. I am wondering if this is right or am I doing something wrong. So far in my character I have 3 things that needs replication. Health, Sprinting and Changing the speed of the player.

So i have 4 functions to replicate the health (SetHealth and ServerSetHealth() + Validation and Implementation). 4 more to change the bool bIsSprinting and 4 more to set the speed of the character when key is pressed. That resulted in 4 \* 3 = 12 functions. They are not complex or anything but as far as I know, when a function is called it takes a memory. So if I build a lot of functions wouldn’t that result in a lot of memory taking? Or am I doing something wrong?

I’ve been thinking on improving a little bit the bool and speed of the char like, whenever I set the bool in the RPC function, I set the speed as well -\> solving two problems with one function hehe. But is it ok for the code?

---

<div class="post-metadata">

**Author:** ![Duetoxplode](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Duetoxplode](https://forums.unrealengine.com/u/Duetoxplode)\
**Post date:** [March 12, 2016, 3:46am UTC](https://forums.unrealengine.com/t/network-programming-a-lot-of-functions-and-code-or-something-is-wrong/57950/2 "2016-03-12T03:46:18Z")

</div>

It sounds like you what you are looking for is Replication.

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

You are achieving replication through RPCs, which also works. If you want to clean up the code a little it’s simpler to set the variables to be replicated.

1. Add UPROPERTY(Replicated) above your variable that you want to be replicated.
2. Implement GetLifetimeReplicatedProps(TArray\< FLifetimeProperty \> & OutLifetimeProps) const
3. Add DOREPLIFETIME(AReplicatedActor, bIsSprinting); in GetLifetimeReplicatedProps

In order for a value to be replicated, it needs to be modified on the server and is then replicated to all clients.  
UPROPERTY(ReplicatedUsing=OnRep\_Flag) also exists, which will call OnRep\_Flag() everytime the variable is replicated.

---

<div class="post-metadata">

**Author:** ![Young\_Wolf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Young\_Wolf](https://forums.unrealengine.com/u/Young_Wolf)\
**Post date:** [March 12, 2016, 10:20am UTC](https://forums.unrealengine.com/t/network-programming-a-lot-of-functions-and-code-or-something-is-wrong/57950/3 "2016-03-12T10:20:16Z")

</div>

Yeah I figured it out, the code get a lot more clean with replicating variables. Thanks
