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"

Player has no Playerstate


I am trying to implement a Lobby system for my game and it's going pretty well so far. I can Host a game and choose a game to join from a server browser.

I have following setup.

MenuLevel: Default Startup Level where you can Host or join a game

LobbyLevel: When you created or joined a session you are placed in the LobbyLevel

The Lobbylevel has it's own GameMode, PlayControllerClass and PlayerState class.

When I Host a game (create a session) everything works fine and a new PlayerController with PlayerState is created.

When I join a game (join session) a PlayerController is created but there is no PlayerState.

I try to access the PlayerState in the BeginPlay function of my PlayerController.

 void AGamePlayerController::BeginPlay()
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Hallo"))); 
     if (PlayerState)
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("PLAYERSTATE")));
     else {
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("NOT PLAYERSTATE")));

I dont have any explenation for this. The only thing I can imagin is the way I join the Lobby. As Host I call OpenLevel() and as Client a call ClientTravel().

Product Version: UE 4.11 Preview
more ▼

asked Feb 10 '16 at 11:08 AM in C++ Programming

avatar image

33 6 7 11

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

2 answers: sort voted first

Ok I found the problem!

Because the PlayerState is created on the server and replicated to the client it takes some time till everything is ready to work.

I checked by just checking the PlayerState in the TickFunction. Around the 2nd tick everything should be initialized fine.

more ▼

answered Feb 10 '16 at 12:31 PM

avatar image

33 6 7 11

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

I gave an alternative solution in this question to checking/polling in Tick.Instead of polling, my solution for solving the issue where PlayerState was null/unavailable until a few frames after BeginPlay was to put my logic in an overridden version of ACharacter::OnRep_PlayerState(). This gets called as soon as the PlayerState is first assigned, or ever changes. No need to pollute your Tick method or have perf issues of checking it every frame, even when you don't need to.

more ▼

answered Mar 16 '19 at 04:17 PM

avatar image

6 1 2

(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