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"

Create Player - Work half the time.

Hi everybody,

So, I'm currently trying to make a local two player shared screen setup. Player 1 is all good, no problem. The problem is with player 2, it work ... half the time. When I play (new editor windows). half the time I do get my second player/character, half the time I do not (and it come down to the "Is Valid" being negative in that case) I have tried to delay the execution of SpawnP2, or delay right after CreatePlayer. Still got it to work half the time. It seems random, I guess it's not, is it related to my computer resources ? The order the game process something ?

PS : the current setup make use of an BlankPawn as default, that is destroy and replaced by the DF-BaseCharacter. Reason being later I will get the player to choose witch character they want to play with.

Thanks.

alt text

Product Version: UE 4.15
Tags:
screenshot_84.png (304.1 kB)
more ▼

asked Apr 14 '17 at 09:49 AM in Blueprint Scripting

avatar image

Theblacktiger
98 8 12 13

avatar image Benergy Apr 14 '17 at 03:03 PM

Stupid question: When you expand the "Create Player" node, is "Spawn Pawn" checked?

avatar image Theblacktiger Apr 14 '17 at 03:44 PM

Yes it is. When not, it just never work (of course :D)

More information : I started the game 49 times and got :

  • 21 Valid

  • 28 Is Not Valid

I tried to add Delay at various moment, doesn't change anything.


Here a record for the 49 runs. (Sorry for the slower connection)

alt text link text

avatar image Benergy Apr 15 '17 at 07:14 AM

I tried to reproduce this failure but it works on my machine. I tried it like 20 times but everytime both actors were spawned. Can you share how your spawning events are called?

avatar image Theblacktiger Apr 15 '17 at 07:55 AM

Sure ! thanks for trying to help. So the spawn event are called from the level blueprint on begin play. I figured that, in my gamemode, I can branch the "Is Not Valid" to the "Spawn actor" directly, without the "destroy actor" At the end it work, but it still bugs me to not understand why half the time the "Create player" got no valid pawn.

I have checked with the debug tool to watch the return value of :

  • Create player

  • Get controlled pawn

The "create player" always return :

 DF-PlayerController_C'/Game/Levels/UEDPIE_0_ProtoOne.ProtoOne:PersistentLevel.DF-PlayerController_C_1'

The "get controlled pawn" return half the time None and the other half a similar reference as above.

alt text

screenshot_91.png (147.1 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Okay, although your program runs as wanted I digged a bit into the source code to find the source of this behaviour. So what I think is happening is that your second player controller is created as a spectating one half the time. For spectating controllers no pawn is spawned. To override this strange behaviour consistently, I would check "Spawn Players as Spectators" in your game mode details. Then, you can override the event OnPostLogin which should guarantee that you have a valid player controller. I came up with something like this:

alt text

This of course only works if you have enough player starts to iterate through ;) And I don't know the behaviour in multiplayer games, because creating players, controllers, spawning default pawns, etc. is bound to network code, so chances are this only executed on the server, but I really don't know.

And to create the second player, you can simply call "Create Player" after Begin Play (e.g. in your level blueprint).

Alternatively, you can override "Handle Starting New Player" in your game mode. This is the original implementation:

 void AGameModeBase::HandleStartingNewPlayer_Implementation(APlayerController* NewPlayer)
 {
     // If players should start as spectators, leave them in the spectator state
     if (!bStartPlayersAsSpectators && !MustSpectate(NewPlayer) && PlayerCanRestart(NewPlayer))
     {
         // Otherwise spawn their pawn immediately
         RestartPlayer(NewPlayer);
     }
 }

So you can override this in your blueprint and call "Restart Player" everytime instead. Should also work, but I havn't tried.

screenshot.png (90.9 kB)
more ▼

answered Apr 15 '17 at 02:38 PM

avatar image

Benergy
831 21 4 29

avatar image Theblacktiger Apr 15 '17 at 04:35 PM

Thanks for your answer ! I'll try that first time in the morning tomorow and let you know more. ;-)

avatar image Theblacktiger Apr 16 '17 at 04:45 AM

So. The "spawn players as spectator" was off already.

Adding the "Event OnPosLogin" seems to get rid of the problem.

Didn't try to override the code as I don't know how to do so. Accepted answer. Thanks again dude ;-)

avatar image freddy91 5 days ago

Worked nicely for me on 4.19! Thanks! :)

(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