每天学习亿点点day 9:UE4 的Pawn源码解析

1. Pawn指的是我们玩家能够possess的类

2.

Remarks

Pawn is the base class of all actors that can be possessed by players or AI. They are the physical representations of players and creatures in a level.

Variables

  NameDescription

Public variable

TSubclassOfAC... 

AIControllerClass

Default class to use when pawn is controlled by AI.

Public variable

float 

AllowedYawError

Max difference between pawn's Rotation.Yaw and GetDesiredRotation().Yaw for pawn to be considered as having reached its desired rotation

Public variable

EAutoPossessAI

 

AutoPossessAI

Determines when the Pawn creates and is possessed by an AI Controller (on level start, when spawned, etc).

Public variable

TEnumAsByteEA... 

AutoPossessPlayer

Determines which PlayerController, if any, should automatically possess the pawn when the level starts or when the pawn is spawned.

Public variable

float 

BaseEyeHeight

Base eye height above collision center.

Public variable

uint32: 1 

bCanAffectNavigationGeneration

If set to false (default) given pawn instance will never affect navigation generation.

Public variable

float 

BlendedReplayViewPitch

Playback of replays writes blended pitch to this, rather than the RemoteViewPitch.

Public variable

uint32: 1 

bUseControllerRotationPitch

If true, this Pawn's pitch will be updated to match the Controller's ControlRotation pitch, if controlled by a PlayerController.

Public variable

uint32: 1 

bUseControllerRotationRoll

If true, this Pawn's roll will be updated to match the Controller's ControlRotation roll, if controlled by a PlayerController.

Public variable

uint32: 1 

bUseControllerRotationYaw

If true, this Pawn's yaw will be updated to match the Controller's ControlRotation yaw, if controlled by a PlayerController.

Protected variable

FVector

 

ControlInputVector

Accumulated control input vector, stored in world space.

Public variable

AController ... 

Controller

Controller currently possessing this Actor

Protected variable

FVector

 

LastControlInputVector

The last control input vector that was processed by ConsumeMovementInputVector().

Public variable

AController ... 

LastHitBy

Controller of the last Actor that caused us damage.

Public variable

uint8

 

RemoteViewPitch

Replicated so we can see where remote clients are looking.

Constructors

 NameDescription

Public function

APawn

(
    const FObjectInitializer& ObjectIn...
)

Default UObject constructor.

Functions

  NameDescription

Public function Virtual

void

 
AddControllerPitchInput

(
    float Val
)

Add input (affecting Pitch) to the Controller's ControlRotation, if it is a local PlayerController.

Public function Virtual

void

 
AddControllerRollInput

(
    float Val
)

Add input (affecting Roll) to the Controller's ControlRotation, if it is a local PlayerController.

Public function Virtual

void

 
AddControllerYawInput

(
    float Val
)

Add input (affecting Yaw) to the Controller's ControlRotation, if it is a local PlayerController.

Public function Virtual

void

 
AddMovementInput

(
    FVector WorldDirection,
    float ScaleValue,
    bool bForce
)

Add movement input along the given world direction vector (usually normalized) scaled by 'ScaleValue'.

Public function Virtual

FVector

 
ConsumeMovementInputVector()
 

Returns the pending input vector and resets it to zero.

Protected function Virtual

UInputCompon...  CreatePlayerInputComponent()
 

Creates an InputComponent that can be used for custom input bindings.

Protected function Virtual

void

 
DestroyPlayerInputComponent()
 

Destroys the player input component and removes any references to it.

Public function Virtual

void

 
DetachFromControllerPendingDestroy()
 

Call this function to detach safely pawn from its controller, knowing that we will be destroyed soon.

Public function Virtual

void

 
DisplayDebug

(
    UCanvas* Canvas,
    const FDebugDisplayInfo& DebugDisp...,
    float& YL,
    float& YPos
)

 

Public function Virtual

void

 
FaceRotation

(
    FRotator NewControlRotation,
    float DeltaTime
)

Updates Pawn's rotation to the given rotation, assumed to be the Controller's ControlRotation.

Public function Virtual Const

FRotator

 
GetBaseAimRotation()
 

Return the aim rotation for the Pawn.

Public function Const

AController ...  GetController()
 

Returns controller for this actor.

Public function Const

T *  GetController()
 

Returns controller for this actor cast to the template type. May return NULL is the cast fails.

Public function Const

FRotator

 
GetControlRotation()
 

Get the rotation of the Controller, often the 'view' rotation of this Pawn.

Protected function Virtual Const

AController ...  GetDamageInstigator

(
    AController* InstigatedBy,
    const UDamageType& DamageType
)

Get the controller instigating the damage.

Public function Virtual Const

float  GetDefaultHalfHeight()
 

Returns The half-height of the default Pawn, scaled by the component scale.

Public function

FVector

 
GetGravityDirection()
 

Returns vector direction of gravity

Public function Const

FVector

 
GetLastMovementInputVector()
 

Return the last input vector in world space that was processed by ConsumeMovementInputVector(), which is usually done by the Pawn or PawnMovementComponent.

Public function Virtual Const

UPrimitiveCo...  GetMovementBase()
 

Return PrimitiveComponent we are based on (standing on, attached to, and moving on).

Public function Static

AActor *  GetMovementBaseActor

(
    const APawn* Pawn
)

Gets the owning actor of the Movement Base Component on which the pawn is standing.

Public function Virtual Const

UPawnMovemen...  GetMovementComponent()
 

Return our PawnMovementComponent, if we have one.

Public function Virtual Const

UPawnNoiseEm...  GetPawnNoiseEmitterComponent()
 

Return our PawnNoiseEmitterComponent, if any.

Public function Virtual Const

APhysicsVolu...  GetPawnPhysicsVolume()
 

Return Physics Volume for this Pawn

Public function Virtual Const

FVector

 
GetPawnViewLocation()
 

Returns Pawn's eye location

Public function Const

FVector

 
GetPendingMovementInputVector()
 

Return the pending input vector in world space.

Public function Const

APlayerState...  GetPlayerState()
 

If Pawn is possessed by a player, returns its Player State.

Public function Const

T *  GetPlayerState()
 

Templated convenience version of GetPlayerState.

Public function Const

T *  GetPlayerStateChecked()
 

Templated convenience version of GetPlayerState which checks the type is as presumed.

Public function Virtual Const

FRotator

 
GetViewRotation()
 

Get the view rotation of the Pawn (direction they are looking, normally Controller->ControlRotation).

Public function Virtual Const

bool

 
InFreeCam()
 

Returns true if player is viewing this Pawn in FreeCam

Public function Const

bool

 
InputEnabled()
 

Whether this Pawn's input handling is enabled.

Public function

void

 
Internal_AddMovementInput

(
    FVector WorldAccel,
    bool bForce
)

Internal function meant for use only within Pawn or by a PawnMovementComponent.

Public function

FVector

 
Internal_ConsumeMovementInputVector()
 

Internal function meant for use only within Pawn or by a PawnMovementComponent.

Public function Const

FVector

 
Internal_GetLastMovementInputVector()
 

Internal function meant for use only within Pawn or by a PawnMovementComponent.

Public function Const

FVector

 
Internal_GetPendingMovementInputVector()
 

Internal function meant for use only within Pawn or by a PawnMovementComponent.

Public function Virtual Const

bool

 
IsBotControlled()
 

Returns true if controlled by a bot.

Public function Virtual Const

bool

 
IsLocallyControlled()
 

Returns true if controlled by a local (not network) Controller.

Public function Virtual Const

bool

 
IsMoveInputIgnored()
 

Helper to see if move input is ignored.

Public function Const

bool

 
IsPawnControlled()
 

Check if this actor is currently being controlled at all (the actor has a valid Controller)

Public function Virtual Const

bool

 
IsPlayerControlled()
 

Returns true if controlled by a human player (possessed by a PlayerController).

Public function Const

FVector

 
K2_GetMovementInputVector()
 

(Deprecated) Return the input vector in world space.

Public function

void

 
MoveIgnoreActorAdd

(
    AActor* ActorToIgnore
)

Add an Actor to ignore by Pawn's movement collision

Public function

void

 
MoveIgnoreActorRemove

(
    AActor* ActorToIgnore
)

Remove an Actor to ignore by Pawn's movement collision

Public function Virtual

void

 
OnRep_Controller()
 

Called when Controller is replicated

Public function Virtual

void

 
OnRep_PlayerState()
 

PlayerState Replication Notification Callback

Public function Virtual

void

 
PawnClientRestart()
 

Tell client that the Pawn is begin restarted.

Public function

void

 
PawnMakeNoise

(
    float Loudness,
    FVector NoiseLocation,
    bool bUseNoiseMakerLocation,
    AActor* NoiseMaker
)

Inform AIControllers that you've made a noise they might hear (they are sent a HearNoise message if they have bHearNoises==true) The instigator of this sound is the pawn which is used to call MakeNoise.

Public function Virtual

void

 
PawnStartFire

(
    uint8 FireModeNum
)

Handle StartFire() passed from PlayerController

Public function Virtual

void

 
PossessedBy

(
    AController* NewController
)

Called when this Pawn is possessed. Only called on the server (or in standalone).

Public function Virtual

bool

 
ReachedDesiredRotation()
 

Return true if yaw is within AllowedYawError of desired yaw

Public function Virtual

void

 
RecalculateBaseEyeHeight()
 

Set BaseEyeHeight based on current state.

Public function

void

 
ReceivePossessed

(
    AController* NewController
)

Event called when the Pawn is possessed by a Controller (normally only occurs on the server/standalone).

Public function

void

 
ReceiveUnpossessed

(
    AController* OldController
)

Event called when the Pawn is no longer possessed by a Controller.

Public function Virtual

void

 
Restart()
 

Called when the Pawn is being restarted (usually by being possessed by a Controller).

Public function

void

 
SetCanAffectNavigationGeneration

(
    bool bNewValue,
    bool bForceUpdate
)

Use SetCanAffectNavigationGeneration to change this value at runtime.

Public function Virtual

void

 
SetPlayerDefaults()
 

Make sure pawn properties are back to default.

Public function

void

 
SetPlayerState

(
    APlayerState* NewPlayerState
)

Set the Pawn's Player State.

Public function

void

 
SetRemoteViewPitch

(
    float NewRemoteViewPitch
)

Set Pawn ViewPitch, so we can see where remote clients are looking. Maps 360.0 degrees into a byte

Protected function Virtual

void

 
SetupPlayerInputComponent

(
    UInputComponent* PlayerInputCo...
)

Allows a Pawn to set up custom input bindings.

Public function Virtual Const

bool

 
ShouldTakeDamage

(
    float Damage,
    FDamageEvent const& DamageEvent,
    AController* EventInstigator,
    AActor* DamageCauser
)

Return true if we are in a state to take damage (checked at the start of TakeDamage. Subclasses may check this as well if they override TakeDamage and don't want to potentially trigger TakeDamage actions by checking if it returns zero in the super class.

Public function Virtual

void

 
SpawnDefaultController()
 

Spawn default controller for this Pawn, and get possessed by it.

Public function Virtual

void

 
TurnOff()
 

Freeze pawn - stop sounds, animations, physics, weapon firing

Public function Virtual

void

 
UnPossessed()
 

Called when our Controller no longer possesses us.

Public function

void

 
UpdateNavAgent()
 

Updates MovementComponent's parameters used by navigation system

Public function Virtual

void

 
UpdateNavigationRelevance()
 

Update all components relevant for navigation generators to match bCanAffectNavigationGeneration flag

Overridden from AActor

  NameDescription

Public function Virtual

void

 
BecomeViewTarget

(
    APlayerController* PC
)

Called when this actor becomes the given PlayerController's ViewTarget.

Public function Virtual Const

bool

 
CanBeBaseForCharacter

(
    APawn* APawn
)

Overridden to defer to the RootComponent's CanCharacterStepUpOn setting if it is explicitly Yes or No.

Public function Virtual

void

 
Destroyed()
 

Called when this actor is explicitly being destroyed during gameplay or in the editor, not called during level streaming or gameplay ending

Public function Virtual

void

 
DisableInput

(
    APlayerController* PlayerContr...
)

Removes this actor from the stack of input being handled by a PlayerController.

Public function Virtual

void

 
EditorApplyRotation

(
    const FRotator& DeltaRotation,
    bool bAltDown,
    bool bShiftDown,
    bool bCtrlDown
)

Called by ApplyDeltaToActor to perform an actor class-specific operation based on widget manipulation.

Public function Virtual

void

 
EnableInput

(
    APlayerController* PlayerContr...
)

Pushes this actor on to the stack of input being handled by a PlayerController.

Public function Virtual

void

 
EndPlay

(
    const EEndPlayReason::Type EndPlayR...
)

Overridable function called whenever this actor is being removed from a level

Public function Virtual Const

void

 
GetActorEyesViewPoint

(
    FVector& OutLocation,
    FRotator& OutRotation
)

Returns the point of view of the actor.

Public function Virtual Const

FString

 
GetHumanReadableName()
 

Returns the human readable string representation of an object.

Public function Virtual Const

UNetConnecti...  GetNetConnection()
 

Get the owning connection used for communicating between client/server

Public function Virtual Const

const AActor...  GetNetOwner()
 

Return the actor responsible for replication, if any. Typically the player controller

Public function Virtual

UPlayer *...  GetNetOwningPlayer()
 

Return the owning UPlayer (if any) of this actor.

Public function Virtual Const

FVector

 
GetVelocity()
 

Returns velocity (in cm/s (Unreal Units/second) of the rootcomponent if it is either using physics or has an associated MovementComponent

Public function Virtual Const

bool

 
IsBasedOnActor

(
    const AActor* Other
)

Iterates up the movement base chain to see whether or not this Actor is based on the given Actor, defaults to checking attachment

Public function Virtual Const

bool

 
IsNetRelevantFor

(
    const AActor* RealViewer,
    const AActor* ViewTarget,
    const FVector& SrcLocation
)

Checks to see if this actor is relevant for a specific network connection

Public function Virtual

void

 
OutsideWorldBounds()
 

Called when the Actor is outside the hard limit on world bounds

Public function Virtual

void

 
PostInitializeComponents()
 

Allow actors to initialize themselves on the C++ side after all of their components have been initialized, only called during gameplay

Public function Virtual

void

 
PostNetReceiveLocationAndRotation()
 

Update location and rotation from ReplicatedMovement. Not called for simulated physics!

Public function Virtual

void

 
PostNetReceiveVelocity

(
    const FVector& NewVelocity
)

Update velocity - typically from ReplicatedMovement, not called for simulated physics!

Public function Virtual

void

 
PostRegisterAllComponents()
 

Called after all the components in the Components array are registered, called both in editor and during gameplay

Public function Virtual

void

 
PreInitializeComponents()
 

Called right before components are initialized, only called during gameplay

Public function Virtual

void

 
PreReplication

(
    IRepChangedPropertyTracker& Change...
)

Called on the actor right before replication occurs.

Public function Virtual

void

 
Reset()
 

Reset actor to initial state - used when restarting level without reloading.

Public function Virtual Const

bool

 
ShouldTickIfViewportsOnly()
 

If true, actor is ticked even if TickType==LEVELTICK_ViewportsOnly

Public function Virtual

float  TakeDamage

(
    float DamageAmount,
    FDamageEvent const& DamageEvent,
    AController* EventInstigator,
    AActor* DamageCauser
)

Apply damage to this actor.

Public function Virtual

void

 
TeleportSucceeded

(
    bool bIsATest
)

Called from TeleportTo() when teleport succeeds

Overridden from UObject

  NameDescription

Public function Virtual Const

void

 
GetLifetimeReplicatedProps

(
    TArrayFLifetimeProperty >& OutLi...
)

Returns the properties used for network replication, this needs to be overridden by all actor classes with native replicated properties

Public function Virtual

void

 
PostEditChangeProperty

(
    FPropertyChangedEvent& PropertyCha...
)

Called when a property on this object has been modified externally

Public function Virtual

void

 
PostLoad()
 

Do any object-specific cleanup required immediately after loading an object.

Overridden from INavAgentInterface

  NameDescription

Public function Virtual Const

void

 
GetMoveGoalReachTest

(
    const AActor* MovingActor,
    const FVector& MoveOffset,
    FVector& GoalOffset,
    float& GoalRadius,
    float& GoalHalfHeight
)

Get cylinder for testing if actor has been reached

Public function Virtual Const

FVector

 
GetNavAgentLocation()
 

Basically retrieved pawn's location on navmesh

Public function Virtual Const

const FNavAg...  GetNavAgentPropertiesRef()
 

Retrieves FNavAgentProperties expressing navigation props and caps of represented agent the function will be renamed to GetNavAgentProperties in 4.8.

Deprecated Functions

  NameDescription

Public function Const

bool

 
IsControlled()
 

IsControlled is deprecated. To check if this pawn is controlled by anything, then call IsPawnControlled. To check if this pawn is controlled only by the player then call IsPlayerControlled

Public function

void

 
LaunchPawn

(
    FVector LaunchVelocity,
    bool bXYOverride,
    bool bZOverride
)

LaunchPawn is deprecated. For Characters, use LaunchCharacter() instead.

See Also

posted @ 2021-05-29 14:25  Tonarinototoro  阅读(403)  评论(0编辑  收藏  举报