UNREAL 多人在綫更换pawn(possess pawn)

unreal engine 多人在线游戏中切换controller的pawn

踩坑后的注意点

  • Possess只能在Server执行
  • Possess pawn时,要从GetPlayerState()获取PlayerState的controller,然后用这个controller posses想要的pawn,否则就是server的controller possess 你想要的pawn了

示例

// SERVER possess new pawn
 if (InCharacter->GetLocalRole() == ROLE_Authority)
 {
  
  // 获取当前要unPossess pawn 的controller
   const auto ClientController = InCharacter->GetPlayerState()->GetPawn()->GetController();

  // client的controller possess 新的pawn
   ClientController->Possess(NewPawn);
   
   InCharacter->GetCharacterMovement()->DisableMovement();
   InCharacter->GetCapsuleComponent()->SetEnableGravity(false);
   
 }

    

你可能感兴趣的:(unreal,engine,unreal4,unreal,游戏)