# How to declare a variable that only exists in the server

**URL:** <https://forums.unrealengine.com/t/how-to-declare-a-variable-that-only-exists-in-the-server/472659>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 9, 2020, 12:11pm UTC](https://forums.unrealengine.com/t/how-to-declare-a-variable-that-only-exists-in-the-server/472659 "2020-10-09T12:11:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cloodshop](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cloodshop](https://forums.unrealengine.com/u/cloodshop)\
**Post date:** [October 9, 2020, 12:11pm UTC](https://forums.unrealengine.com/t/how-to-declare-a-variable-that-only-exists-in-the-server/472659/1 "2020-10-09T12:11:38Z")

</div>

Suppose I have a class, such as a player controller. It exists in both the server and the client. But it has some variables stored only on the server. How should I define such a variable?

---

<div class="post-metadata">

**Author:** ![Gubidonius](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gubidonius/32/742377_2.png) [@Gubidonius](https://forums.unrealengine.com/u/Gubidonius)\
**Post date:** [May 21, 2024, 1:52pm UTC](https://forums.unrealengine.com/t/how-to-declare-a-variable-that-only-exists-in-the-server/472659/3 "2024-05-21T13:52:49Z")

</div>

A little necroposting

In Unreal, class definitions are shared between client and server for consistency in object structure across the network

If it’s really needed for some memory optimizations, you could try to do some hacks like

```auto
#if WITH_SERVER_CODE
int ServerOnlyVariable;
#endif

```

but it’s really not recommended

---

<div class="post-metadata">

**Author:** ![Gubidonius](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gubidonius/32/742377_2.png) [@Gubidonius](https://forums.unrealengine.com/u/Gubidonius)\
**Post date:** [May 23, 2024, 1:07pm UTC](https://forums.unrealengine.com/t/how-to-declare-a-variable-that-only-exists-in-the-server/472659/4 "2024-05-23T13:07:02Z")

</div>

And just in case, if you were to use structs, it would be really beneficial to exclude some fields from replication

you could do it like this:

```auto
USTRUCT()
struct FMyStruct
{
	GENERATED_BODY()
 
	UPROPERTY()
	int32 ReplicatedProperty;
 
	// Not Replicated even though encompassing struct is Replicated
	UPROPERTY(NotReplicated)
	int32 NotReplicatedProperty;
};

```
