인프런 커뮤니티 질문&답변

themoon007님의 프로필 이미지

작성한 질문수

이득우의 언리얼 프로그래밍 Part3 - 네트웍 멀티플레이 프레임웍의 이해

14강 캐릭터 아이템과 스탯의 구현

액터에 우선권을 사용자 설정할 수 있었나요?

해결된 질문

23.12.08 16:26 작성

·

171

0

다시 쭉 보다 보니 궁금한게 하나씩 계속 나오는 것 같습니다...

 

Owner 설정해서 배율을 높히는 것 말고 다른 manual적 방법이 있나요?

답변 1

1

이득우님의 프로필 이미지
이득우
지식공유자

2023. 12. 09. 11:16

NetPriority변수 또는 GetNetPriority 함수를 오버라이드해 구현하면 됩니다.
액터의 기본 우선권 값은 1이며, 최종 설정 값 산출 로직은 다음과 같습니다.

 

float AActor::GetNetPriority(const FVector& ViewPos, const FVector& ViewDir, AActor* Viewer, AActor* ViewTarget, UActorChannel* InChannel, float Time, bool bLowBandwidth)
{
	if (bNetUseOwnerRelevancy && Owner)
	{
		// If we should use our owner's priority, pass it through
		return Owner->GetNetPriority(ViewPos, ViewDir, Viewer, ViewTarget, InChannel, Time, bLowBandwidth);
	}

	if (ViewTarget && (this == ViewTarget || GetInstigator() == ViewTarget))
	{
		// If we're the view target or owned by the view target, use a high priority
		Time *= 4.f;
	}
	else if (!IsHidden() && GetRootComponent() != NULL)
	{
		// If this actor has a location, adjust priority based on location
		FVector Dir = GetActorLocation() - ViewPos;
		float DistSq = Dir.SizeSquared();

		// Adjust priority based on distance and whether actor is in front of viewer
		if ((ViewDir | Dir) < 0.f)
		{
			if (DistSq > NEARSIGHTTHRESHOLDSQUARED)
			{
				Time *= 0.2f;
			}
			else if (DistSq > CLOSEPROXIMITYSQUARED)
			{
				Time *= 0.4f;
			}
		}
		else if ((DistSq < FARSIGHTTHRESHOLDSQUARED) && (FMath::Square(ViewDir | Dir) > 0.5f * DistSq))
		{
			// Compute the amount of distance along the ViewDir vector. Dir is not normalized
			// Increase priority if we're being looked directly at
			Time *= 2.f;
		}
		else if (DistSq > MEDSIGHTTHRESHOLDSQUARED)
		{
			Time *= 0.4f;
		}
	}

	return NetPriority * Time;
}