Announcement

Collapse
No announcement yet.

Spectator pawn on client side

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Thanks Alex.

    Another update: If you're overriding SetPawn(APawn* InPawn) don't check for nullptr. I just ran into another case where the spectator pawn was created, but the client was not possessing it.

    This is what I had:
    Code:
    void ABasePlayerController::SetPawn(APawn* InPawn)
    {
        if (InPawn == nullptr) // remove this
              return;
    
        Super::SetPawn(InPawn);
        // ...
    }

    Comment


      #17
      Originally posted by AlexLee89 View Post
      I've been having some trouble with this issue for a while and came up with the solution after extensive breakpoints.

      If you're SpectatorPawn is not spawning properly, it's because you're not calling ChangeState(NAME_Spectating) on the server side.

      If you're SpectatorPawn spawns correctly and everything is working except the camera position, you need to set the ViewTarget back to SpectatorPawn. What basically happens is after the SpectatorPawn is spawned and set as a ViewTarget on the client side, a delayed Controller::OnRep_Pawn(null) calls PlayerController::SetPawn(null), which then invokes AutoManageActiveTarget(this), changing the PlayerController location as the ViewTarget.

      I've made a pull request to the Unreal Source engine which fixes the issue 5 days ago, but for now, you can easily change the ViewTarget issue by overriding the OnRep_Pawn() on your controller class, calling its base, then setting the ViewTarget Back to the Spectator Pawn if it's in a spectating state.


      void AMyPlayerController::OnRep_Pawn()
      {
      Super::OnRep_Pawn();

      if (GetStateName() == NAME_Spectating)
      {
      AutoManageActiveCameraTarget(GetSpectatorPawn());
      }
      }
      Thanks this solved my issue, any news on when this gets fixed?
      I'm using 4.22 and I seem to still have this problem.

      Comment

      Working...
      X