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?
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
#if WITH_SERVER_CODE
int ServerOnlyVariable;
#endif
but it’s really not recommended
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:
USTRUCT()
struct FMyStruct
{
GENERATED_BODY()
UPROPERTY()
int32 ReplicatedProperty;
// Not Replicated even though encompassing struct is Replicated
UPROPERTY(NotReplicated)
int32 NotReplicatedProperty;
};