No announcement yet.

A different character for each player

  • Filter
  • Time
  • Show
Clear All
new posts

    A different character for each player


    I'm trying to set up a simple multiplayer where one player is in VR and the other is not. Basically, I just want to spawn a different character for each player. I was trying to spawn different pawns depending on 'is server' bool (if host - take this pawn, if client - take this pawn).

    I'm stuck and I can't figure out how to check this bool. I followed this tutorial:

    Where exactly this feature is solved. However, I can't find where the variable 'is host?' is assigned.

    Please help!


    I don't know if it can help you but maybe you just have to tell the Host to take this pawn and the "joiner" client take that pawn ?

    Or in your player controller (I hope it's the same for both...) set On Begin play, a branch with a bool call : AmIHost? if true set spawn pawn to the one you want and if it's false spawn the pawn you want too


      I did exactly this before, but somehow I get 'true' two times, for both players as if both are hosts...


        Cause you have to set if they are host or client in you lobby menu/level


          Oh right ^^ is it something simple? Could explain me here how to do it?


            If you have the same PlayerController for the both maps you can :

            In your PlayerController :
            - Create a variable and name it : AmITheHost? (set it to false)
            - on your BeginEvent, put a Branch (B+Click) and check if AmITheHost? is true or false
            - if it's true, spawn pawn 1 and posses it by PlayerController (self reference I think)
            - if it's false, spawn pawn 2 and posses it by PlayerController (self reference I think)

            Now, on your level/lobby where people join the game, make a widget, and when the player click on "host a game" :
            - OnClickedEvent, cast to player controller, and set AmITheHost? on true

            Make that and tell me if it work


              Ok I did it inside PlayerController (build in 'is Server' bool), because I think that after I host a game and Open Level, or Join session all variables are back to default (it didn't work).

              This is almost working xd Should I check Run Dedicated Server in the Editor? I got all spawns doubled so twice true (server) and twice fales (client). Two characters are spawned only after hosting a room, without a client yet.

              The second player doesn't spawn properly - no pawn, and camera is like on a default 0,0,0 position. I think it doesn't possess properly.

              Those are however a bit hard to explain issues so I don't think you will be able to help me with them


                ho... I understand. Sorry I didn't remember this officiel multiplayer tutorial -_-
                When I talk to you about the host and the player is cause I use another multiplayer project now, so I can make a room where players can join... So you can tell wich one is the host and wich one is the clients.
                But with your multiplayer project you "simulate" multiplayer game.

                I think you should take another way...

                Make the host launch the game and make a Level event :

                On this level blueprint, cast to player controller to make a widget

                And choose if you are the pawn 1 or pawn 2 here

                Then the second player make the same thing... He join you and choose the second pawn once is in the game with the same widget event

                Tell me what you got


                  Yes this could work, I'd try to set this up.

                  I don't understand why Begin play in my PlayerController is launched twice for Server and twice for Client (or once if I untick Dedicated Server)


                    You can make the default pawn be a "do nothing" pawn (or spectator.) Then the server can decide who gets what pawn class, and update a class property in the playerstate.
                    Then the playerstate will respond to a change of the class property by unpossessing/deleting the currently controlled pawn, and spawing/possessing a new pawn based on that class value.


                      don't click dedicated server. I think it's not good in editor mode


                        Yes jwatte this is probably how this should be set up ^^. Thanks Zoruk for your tips too, I'll try both solutions.

                        How about this Begin play? I have ONLY BeginPlay -> Print String in my PlayerController. I play in Selected Viewport with number of players: 2. No dedicated server. Clean GameMode and Level Blueprint. Default IntPawn. I receive 'Hello' from Server twice and once from Client. Why twice from Server?