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);
}