Download

shooter example IsFirstPerson

Hi can any1 explain how this function works? the Controller->IsLocalPlayerController() will always return false even on the character im controlling

bool AShooterCharacter::IsFirstPerson() const
{
return IsAlive() && Controller && Controller->IsLocalPlayerController();
}

IsLocalPlayerController is a function that tells you if the player controller is controlled locally on your machine or remotely(it belongs to other player and you can’t control it from your game’s instance).
In example, if you connect to a server with 3 other different players, then you will have 4 player controllers, but only yours will return true when IsLocalPlayerController() is called.

IsLocalPlayerController function documentation: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AController/IsLocalPlayerController/index.html

I don’t think that is true. If you connect to a server only your own PlayerController will exist on your machine. Only the server has a reference to all PlayerControllers.

To answer the question. The function name is a bit off. It does not tell if the player is FirsterPerson or ThirdPerson (there is no thirdperson in ShooterGame). It simply returns if the Pawn is controlled by a human or not.
ShooterGame uses this function to determine which Mesh should be visible and how the attachment of weapons work. If IsFirstPerson() returns true, then attach the Weapon to the FirstPersonMesh (Arms). If it returns false -> attach the weapon to the ThirdPersonMesh.

Yes, you’re right. :smiley: So IsLocalPlayerController will return false on server for all controllers and true for your controller on client.

but now my shooter game no networking yet, so by default my current game is the server?

then if im the player hosting the server, the IsFirtPerson will return false, so how to just draw the firstperson mesh instead of the 3rd person mesh if this function will return false?

i checked the IsLocalPlayerController()
bool AController::IsLocalPlayerController() const
{
return false;
}

always return false…

If you want to draw First Person Mesh for controlled player and Third Person Mesh for everyone else you can use SetOwnerNoSee and SetOnlyOwnerSee flags of UPrimitiveComponent class. You can set them either in blueprint or code using functions from UPrimitiveComponent class(https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UPrimitiveComponent/SetOwnerNoSee/index.html and https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UPrimitiveComponent/SetOnlyOwnerSee/index.html).

Then, your first person mesh will be only visible for the player that is controlling your pawn, and third person mesh will be visible to everyone else.

yes, i know , what i meant is I looked at the IsLocalPlayerController() code from Controller.cpp:

bool AController::IsLocalPlayerController() const
{
return false;
}

it will always return false, when will it return true?

i tried to play in both server n client n it never return true

bumpz bumpz

Hi LTE,

Please do not bump threads that have not gone unanswered for 4 or more days. This unnecessarily clutters the forums and makes it extremely difficult to parse through. Thank you!

HI LTE
IsLocalPlayerController() confused me too,I checked it’s definition and it just always returns false,
but when I debug it by using these code :
bool const bFirstPerson = IsFirstPerson();
UE_LOG(LogTemp, Warning, TEXT(“bFirstPerson %d”), bFirstPerson);
I found out it returns false first time ,but returns true second time:

LogOnline:Warning: NULL: Can't start an online game for session (Game) that hasn't been created
LogTemp:Warning: bFirstPerson 0
LogTemp:Warning: bFirstPerson 1
LogOnline:Display: AShooterPlayerController::OnQueryAchievementsComplete(bWasSuccessful = TRUE)

I don't understand where this true value come from ,do you have any idea?  thanks very much

Based on my noobie understanding on the usage of IsLocalPlayerController() on displaying healthbars in a network game.

The function will return true if the character being called in your “screen” is a controller and not a “dummy” representative of other clients. Take for example you are playing a network game with two other players (so total three), in your screen there should be three characters running amok with one being controlled by you. That would be the character with the controller and therefore IsLocalPlayerController() would return true for that while the rest of the two will not have any controllers at all.

IsLocalPlayerController(); will return true for any controller that has Authority on the local instance of the game only.

In Multiplayer - clients only have their own Player Controller, and the Server has the full list of Player Controllers. IsLocalPlayerController() will return true on the server, but ONLY for the Server-Player - not Clients connected to it. If you’re game is not Multiplayer, then the only player has Authority, and therefore the function will return true.

The reason AController::IsLocalPlayerController() returns false, is because ‘AController’ is not the same as ‘APlayerController’. Look at APlayerController.cpp and you will see the code is quite different.

If however, you look at AController::IsLocalController() - it too will return something different.