x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Using UWorld::GetFirstPlayerController to check if the player controller is the local player

So, I've been investigating methods to find if the local player is controlling the current player pawn. It's quite easy on dedicated servers since clients only have one player controller - the one they currently control - but on non dedicated servers where the player is hosting as well as playing it's a little more difficult because the server has player controllers for each pawn. The solution that I currently am working with is to check if UWorld::GetFirstPlayerController is the one that's controlling the pawn, which works out great in testing, but after reading the source of the function it just pulls the first one off the top of an array. Can I assume this method is safe? Is there a better way to find the locally controlled player on a server?

Edit: After some more investigation, I found GEngine->GetGamePlayer(), which I then use to check if the pawn's controller is the ULocalPlayer's controller. I now have a function in my player character class that goes like so:

 bool AALastWatchPlayerCharacter::IsLocalPlayer()
 {
     if (Controller)
     {
         return GEngine->GetGamePlayer(GetWorld(), 0)->PlayerController == Cast<APlayerController>(Controller);
     }
     
     return false;
 }
Product Version: Not Selected
Tags:
more ▼

asked Oct 23 '14 at 03:14 AM in C++ Programming

avatar image

pdylanross
71 5 9 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

After some more investigation, I found GEngine->GetGamePlayer(), which I then use to check if the pawn's controller is the ULocalPlayer's controller. I now have a function in my player character class that goes like so:

 bool AALastWatchPlayerCharacter::IsLocalPlayer()
 {
     if (Controller)
     {
         return GEngine->GetGamePlayer(GetWorld(), 0)->PlayerController == Cast<APlayerController>(Controller);
     }
     
     return false;
 }
more ▼

answered Oct 23 '14 at 08:10 AM

avatar image

pdylanross
71 5 9 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question