APawn::OnRep_Controller
#include "GameFramework/Pawn.h"
Access: public
Specifiers: virtualUFUNCTION
Description
Replication notification called on clients when the Controller property changes. Used to react to possession and unpossession events on the owning client and other remote clients.
Caveats & Gotchas
- • Controllers are not replicated to non-owning clients — only the pawn's Controller pointer is replicated. Remote clients can tell whether the pawn is possessed (Controller != nullptr) but cannot reliably cast to APlayerController or access player-specific state from the controller reference.
- • The previous controller value is not passed in; if you need to compare old vs new you must cache it yourself in a UPROPERTY before the rep notification fires.
- • Call Super::OnRep_Controller() when overriding — the base implementation calls NotifyControllerChanged(), which fires ReceiveControllerChangedDelegate and ReceiveControllerChanged BP events.
Signature
virtual void OnRep_Controller() Return Type
void Example
React to possession on a client C++
void AMyPawn::OnRep_Controller()
{
Super::OnRep_Controller();
// Show or hide local HUD elements based on whether we are now possessed
if (APlayerController* PC = Cast<APlayerController>(Controller))
{
UpdateHUDVisibility(true);
}
else
{
UpdateHUDVisibility(false);
}
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?