当前位置:网站首页>UE small knowledge point controller possess pawn process
UE small knowledge point controller possess pawn process
2022-07-01 09:25:00 【[ascetic monk]】
void AController::Possess(APawn* InPawn)
{
if (!bCanPossessWithoutAuthority && !HasAuthority())
{
FMessageLog("PIE").Warning(FText::Format(
LOCTEXT("ControllerPossessAuthorityOnly", "Possess function should only be used by the network authority for {0}"),
FText::FromName(GetFName())
));
UE_LOG(LogController, Warning, TEXT("Trying to possess %s without network authority! Request will be ignored."), *GetNameSafe(InPawn));
return;
}
REDIRECT_OBJECT_TO_VLOG(InPawn, this);
const APawn* CurrentPawn = GetPawn();
// A notification is required when the current assigned pawn is not possessed (i.e. pawn assigned before calling Possess)
const bool bNotificationRequired = (CurrentPawn != nullptr && CurrentPawn->GetController() == nullptr);
// To preserve backward compatibility we keep notifying derived classed for null pawn in case some
// overrides decided to react differently when asked to possess a null pawn.
// Default engine implementation is to unpossess the current pawn.
OnPossess(InPawn);
// Notify when pawn to possess (different than the assigned one) has been accepted by the native class or notification is explicitly required
APawn* NewPawn = GetPawn();
if (NewPawn != CurrentPawn || bNotificationRequired)
{
ReceivePossess(NewPawn);
OnNewPawn.Broadcast(NewPawn);
}
}void APlayerController::OnPossess(APawn* PawnToPossess)
{
if ( PawnToPossess != NULL &&
(PlayerState == NULL || !PlayerState->IsOnlyASpectator()) )
{
const bool bNewPawn = (GetPawn() != PawnToPossess);
if (GetPawn() && bNewPawn)
{
UnPossess();
}
if (PawnToPossess->Controller != NULL)
{
PawnToPossess->Controller->UnPossess();
}
PawnToPossess->PossessedBy(this);
// update rotation to match possessed pawn's rotation
SetControlRotation( PawnToPossess->GetActorRotation() );
SetPawn(PawnToPossess);
check(GetPawn() != NULL);
if (GetPawn() && GetPawn()->PrimaryActorTick.bStartWithTickEnabled)
{
GetPawn()->SetActorTickEnabled(true);
}
INetworkPredictionInterface* NetworkPredictionInterface = GetPawn() ? Cast<INetworkPredictionInterface>(GetPawn()->GetMovementComponent()) : NULL;
if (NetworkPredictionInterface)
{
NetworkPredictionInterface->ResetPredictionData_Server();
}
AcknowledgedPawn = NULL;
// Local PCs will have the Restart() triggered right away in ClientRestart (via PawnClientRestart()), but the server should call Restart() locally for remote PCs.
// We're really just trying to avoid calling Restart() multiple times.
if (!IsLocalPlayerController())
{
GetPawn()->DispatchRestart(false);
}
ClientRestart(GetPawn());
ChangeState( NAME_Playing );
if (bAutoManageActiveCameraTarget)
{
AutoManageActiveCameraTarget(GetPawn());
ResetCameraMode();
}
}
}void AController::UnPossess()
{
APawn* CurrentPawn = GetPawn();
// No need to notify if we don't have a pawn
if (CurrentPawn == nullptr)
{
return;
}
OnUnPossess();
// Notify only when pawn has been successfully unpossessed by the native class.
APawn* NewPawn = GetPawn();
if (NewPawn != CurrentPawn)
{
ReceiveUnPossess(CurrentPawn);
OnNewPawn.Broadcast(NewPawn);
}
}void APlayerController::OnUnPossess()
{
if (GetPawn() != NULL)
{
if (GetLocalRole() == ROLE_Authority)
{
GetPawn()->SetReplicates(true);
}
GetPawn()->UnPossessed();
if (GetViewTarget() == GetPawn())
{
SetViewTarget(this);
}
}
SetPawn(NULL);
}
void APawn::UnPossessed()
{
AController* const OldController = Controller;
ForceNetUpdate();
SetPlayerState(nullptr);
SetOwner(nullptr);
Controller = nullptr;
// Unregister input component if we created one
DestroyPlayerInputComponent();
// dispatch Blueprint event if necessary
if (OldController)
{
ReceiveUnpossessed(OldController);
}
NotifyControllerChanged();
ConsumeMovementInputVector();
}void ACharacter::UnPossessed()
{
Super::UnPossessed();
if (CharacterMovement)
{
CharacterMovement->ResetPredictionData_Client();
CharacterMovement->ResetPredictionData_Server();
}
// We're no longer controlled remotely, resume regular ticking of animations.
if (Mesh)
{
Mesh->bOnlyAllowAutonomousTickPose = false;
}
}void APawn::PossessedBy(AController* NewController)
{
SetOwner(NewController);
AController* const OldController = Controller;
Controller = NewController;
ForceNetUpdate();
if (Controller->PlayerState != nullptr)
{
SetPlayerState(Controller->PlayerState);
}
if (APlayerController* PlayerController = Cast<APlayerController>(Controller))
{
if (GetNetMode() != NM_Standalone)
{
SetReplicates(true);
SetAutonomousProxy(true);
}
}
else
{
CopyRemoteRoleFrom(GetDefault<APawn>());
}
// dispatch Blueprint event if necessary
if (OldController != NewController)
{
ReceivePossessed(Controller);
NotifyControllerChanged();
}
}void APlayerController::ClientRestart_Implementation(APawn* NewPawn)
{
UE_LOG(LogPlayerController, Verbose, TEXT("ClientRestart_Implementation %s"), *GetNameSafe(NewPawn));
ResetIgnoreInputFlags();
AcknowledgedPawn = NULL;
SetPawn(NewPawn);
if ( (GetPawn() != NULL) && GetPawn()->GetTearOff() )
{
UnPossess();
SetPawn(NULL);
AcknowledgePossession(GetPawn());
return;
}
if ( GetPawn() == NULL )
{
// We failed to possess, ask server to verify and potentially resend the pawn
ServerCheckClientPossessionReliable();
return;
}
// Only acknowledge non-null Pawns here. ClientRestart is only ever called by the Server for valid pawns,
// but we may receive the function call before Pawn is replicated over, so it will resolve to NULL.
AcknowledgePossession(GetPawn());
GetPawn()->Controller = this;
GetPawn()->DispatchRestart(true);
if (GetLocalRole() < ROLE_Authority)
{
ChangeState( NAME_Playing );
if (bAutoManageActiveCameraTarget)
{
AutoManageActiveCameraTarget(GetPawn());
ResetCameraMode();
}
}
}void APlayerController::AcknowledgePossession(APawn* P)
{
if (Cast<ULocalPlayer>(Player) != NULL)
{
AcknowledgedPawn = P;
if (P != NULL)
{
P->RecalculateBaseEyeHeight();
}
ServerAcknowledgePossession(P);
}
}边栏推荐
- 2022.02.15_ Daily question leetcode six hundred and ninety
- Databinding source code analysis
- Short circuit operator lazy evaluation
- 树结构---二叉树2非递归遍历
- Can diffusion models be regarded as an autoencoder?
- Implementation and application of queue
- 2.4 activation function
- nacos简易实现负载均衡
- JS prototype trap
- Pain points and solutions of equipment management in large factories
猜你喜欢

Error org apache. catalina. core. StandardContext. FilterStart start filter exception
![Problems caused by delete and delete[]](/img/d9/a1c3e5ce51ef1be366a973aa42d1f0.png)
Problems caused by delete and delete[]

How to manage fixed assets efficiently in one stop?

js作用域链与闭包

Nacos service configuration and persistence configuration

【pytorch】2.4 卷积函数 nn.conv2d

Dspic30f6014a LCD block display

Understanding and implementation of AVL tree

Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)

【电赛训练】红外光通信装置 2013年电赛真题
随机推荐
计网01-物理层
NoSQL数据库的安装和使用
Principle and application of single chip microcomputer timer, serial communication and interrupt system
In the middle of the year, where should fixed asset management go?
tensorrt yolov5_ trt. Py comments
Principles of Microcomputer - internal and external structure of microprocessor
MapReduce programming basics
Meituan machine test in 2022
Imitation of Baidu search results top navigation bar effect
How to launch circle of friends marketing and wechat group activities
Is it safe to dig up money and make new shares
【pytorch】nn. Crossentropyloss() and nn NLLLoss()
Weidongshan board compilation kernel problem solving
Error org apache. catalina. core. StandardContext. FilterStart start filter exception
Bird recognition app
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的温湿度监控系统
A 419 error occurred in the laravel postman submission form. July 6th, 2020 diary.
js原型继承仅可继承实例而非构造器
ES6-const本质与完全不可改实现(Object.freeze)
2.4 activation function