How do I replicate a function in C++?

I’m trying to make a multiplayer game based off of capture the flag, and I’ve setup a function that can attach the flag to the player, but I can’t figure out how to replicate it. I’ve tried to call UFUNCTION(Client, Reliable) but that doesn’t work. What should I do?

Header:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "SCharacter.generated.h"

UCLASS()
class CAPTURETHEFLAG_API ASCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	// Sets default values for this character's properties
	ASCharacter();

protected:

	UFUNCTION(Client, Reliable)
	void AttachFlagToPlayer();

	// More code...

};

CPP:

#include "SCharacter.h"
#include "Net/UnrealNetwork.h"
#include "SFlag.h"


// Sets default values
ASCharacter::ASCharacter()
{
	// Component setup...
}


// Called every time we want to interact with the flag
void ASCharacter::Interact()
{
	if (AbleToInteract())
	{
		// Code...

		// Attach the flag to ourself
		AttachFlagToPlayer();
	}
}


void ASCharacter::AttachFlagToPlayer_Implementation()
{

	FlagReference->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, WeaponAttachSocketName);
}

//Works on client only
UFUNCTION(Client)
void DoSomething();

//Works on server only
UFUNCTION(Server)
void DoSomething();

//Works on Server and Client
UFUNCTION(NetMulticast)
void DoSomething();
1 Like

I figured it out! I thought a variable that I was trying use was replicated because I marked it as replicated, but it wasn’t being changed on the server, and I guess it does need to be changed on the server to be replicated.