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"

How do I remove a split-screen player?

I'm trying to implement a multiplayer mode with splitscreen. The menu only contains 1 menu pawn. When the player presses the "Multiplayer" button, a new map is loaded and on begin play I call "Create Player" three times.

Everything works great, but when I return to the main menu by hitting escape and opening that map, the screen is still split with 4 player controllers active. I've tried destroying the extra controllers, un-possessing each of them, and trying to call "Quit Game" on each, none of these work and calling quit game crashes the editor.

How can I remove or destroy these players?

Product Version: Not Selected
Tags:
more ▼

asked Jun 11 '14 at 04:39 PM in Blueprint Scripting

avatar image

Tarwine
53 9 12 22

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

5 answers: sort voted first

Sorry for the late response but I figured it out - with help from the ShooterGame example. At the time - it had to be done in C++ it seems.

 void AMultiplayerGameMode::RemoveSplitscreenPlayers()
 {
     const int MaxSplitScreenPlayers = 4;
     ULocalPlayer* PlayersToRemove[MaxSplitScreenPlayers];
     int RemIndex = 0;
 
     for (FConstPlayerControllerIterator Iterator = GEngine->GameViewport->GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
     {
         // Remove only local split screen players
         APlayerController* Controller = *Iterator;
         if (Controller && Controller->IsLocalController() && !Controller->IsPrimaryPlayer())
         {
             
             ULocalPlayer* ExPlayer = Cast<ULocalPlayer>(Controller->Player);
             if (ExPlayer)
             {
                 PlayersToRemove[RemIndex++] = ExPlayer;
                 Controller->PawnPendingDestroy(Controller->GetPawn());
             }
         }
     }
 
     for (int i = 0; i < RemIndex; ++i)
     {
         
         GEngine->GameViewport->RemovePlayer(PlayersToRemove[i]);
     }
     
 }
more ▼

answered Aug 17 '14 at 03:53 AM

avatar image

Tarwine
53 9 12 22

avatar image JonathanADaley Jan 02 '15 at 04:32 AM

Thank you for posting this code. I was having a similar issue and this code allowed me to resolve it. Thanks again.

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

Actually, I have a stupid way to solve this problem: there's a blueprint node for "Execute Console Command" so I used it to execute "DebugRemovePlayer 1". This removes the player exactly how it should. Using string concatenation and a for loop I'd imagine anyone who needs to remove x many local players from their game will be able to do so, but I can't imagine this is good practice.

Since people who work on the engine read these sometimes, why have a "Create Player" blueprint node if you're not going to have a corresponding "Remove Player" one? It seems awfully inconvenient.

more ▼

answered Dec 01 '14 at 06:57 AM

avatar image

WaveParadigm
18 5 7 10

avatar image JonathanADaley Jan 01 '15 at 10:14 PM

The Console Command doesn't work in a Shipping Build.

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

Hey! There is a non-coding way to do that too. Go to Edit-> Project Settings-> Project section-> Maps&Modes-> uncheck the Enable split screen box. Hope this helps (worked for me) Cheers

more ▼

answered Jan 19 '15 at 09:30 AM

avatar image

Peuce
6 1 2

avatar image JGwinner 4 days ago

Perfect! Thank you. The non-coding way is usually the best! Otherwise, you're fighting the engine. Thanks for your response.

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

Destroying the extra controllers? Also in most cases returning to the main menu and then typing debugremoveplayer 3, then debugremoveplayer 2, then debugremoveplayer 1 in that order can fix the issue and restore it back to one player. When it comes down to "Quitting" depending on if that means quitting the session or the game itself, it shouldn't be used on players 2 3 and 4.

If that suggestion doesn't work, you may have to add a extra bit of code to your "multiplayer" code, such as telling the game to remove the three players upon the first player leaving that session.

more ▼

answered Jul 28 '14 at 05:04 PM

avatar image

Twrmois
21 2 3 5

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

Hi Tarwine,

I was wondering if since this point if you have found a way to do it within blueprint. If not then where would I put the code that you have posted above?

Thanks in advance!

more ▼

answered Oct 14 '14 at 07:41 PM

avatar image

StomachBug
6 3 7 7

(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