Replicate Actor Properties

  1. Replicated
    1. 단순 property replicate에 사용
  2. ReplicatedUsing
    1. replicate를 할 때 RepNotify 함수를 제공해야 한다.
    2. 속성이 replicate 될 때마다 RepNotify가 호출된다.
    3. replicate시 추가 작업을 수행할 때 사용
  3. NotReplicated
    1. replicate가 되지 않도록 지정하는 metadata
    2. Replicated Struct 내 특정 속성을 replicated 되지 않도록 할 때 유용함.

Replicate 과정

// Replicated 속성 추가
UPROPERTY(Replicated)
uint32 Health;

//생성자에서 Actor 가 replicated 가능한 상태임을 명시
생성자
{
	bReplicates = true;
}
	
	// GetLifetimeReplicatedProps 함수에서 replicated 할 멤버 정의
void ADerivedActor::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
    Super::GetLifetimeReplicatedProps(OutLifetimeProps);
    DOREPLIFETIME(ADerivedActor, Health);
}

Replicated Using

// ReplicatedUsing 메타데이터 추가
UPROPERTY(ReplicatedUsing=OnRep_HealthUpdate)
uint32 Health;

// RepNotify 함수 추가
UFUNCTION()
void OnRep_HealthUpdate();

// replicate 와 마찬가지로 생성자, GetLifetTimeReplicatedProps 에서 정의
...

void ADerivedActor::OnRep_HealthUpdate()
{
		UE_LOG(LogTemp, Log, TEXT("OnRep_HealthUpdate"))
		// Add custom OnRep logic
}