The problem is that when i set 2 player on UE4 and then i click play, the host player (player 1) was always duplicate, but only when i see it in client window, in the host window is only one -,- !
I try many things but i don’t know why this happens. Anyone can help me ? If you need more info or screenshot tell me.
Sorry my english.
The thing is, this is not the correct way of doing this.
Spawning PlayerActors (DefaultSettings must be set to replicate!) should be done when a player connects and ONLY on the Server.
The Client version will be spawned automatically once the Server spawns the replicated Actor.
How do i know when a Player connects?
The GameMode class has an Event called “PostLogin”. This event is called when the Clients connection has a valid “PlayerController”.
The Event itself passes you this “PlayerController”. GameMode only exists on the Server, so here you want to spawn the PlayerActor
AND also posses the spawned PlayerActor with the passed “PlayerController”.
Similar to spawning, POSSESSING a PlayerActor (Pawn) MUST be done on the SERVER! Not on the Client.
Begin Play and Replicated Actors
The BeginPlay function (and also other automatic functions like the Tick…) must be treated carefully. BeginPlay will be called on the Actor
on both, Server AND Client Side. If you spawn a PlayerActor, that is replicated, the BeginPlay will be called twice. Once on the Server Version
and once on the Client Version of that PlayerActor. To limit functions to the Server Version, you need to use the “SwitchHasAuthority” node
and use the AUTHORITY Pin. Same goes for limiting a call to the Client, for example to Spawn UI only for clients when using a dedicated server,
by using the REMOTE Pin.
What should i do now?
Try downloading my example project “BallBump” that you can find in the Forum Thread that i linked in my Signature below.
There you might be able to find a part where i spawn Players and possess them.
NOTE: If i remember correctly, the “BallBump” saves the “PlayerController” when the Player connects and uses it
later in the “GameState” class to spawn the Players once all awaited players did connect. This might be more than you want and need.
Another project you could check out is the “Multiplayer Shootout” that Epic has in its learn tab.
Thanks you very much for the reply, was very instructive ! I download Ball-Bump and tomorrow i’ll study all the structure. Maybe choose like first project a multiplayer game was too ambitious eheh. Thanks again !
Yes, multiplayer is nothing for a beginner. You first need to learn how the Engine is structured for SinglePlayer Games, and of course learn how to program (Blueprints are C++ :P)
You tell me that now? I had working singleplayer prototype of top down shooter, then i watched multiplayer tutorial, now after about 6 weeks i have again working prototype this time in multiplayer. All singleplayer code is just gone.
Yes multiplayer is not as easy as it looks. And I am definitely downloading that “BallBump” example.
Btw. Dexter87, you can right click on those orange transform pins and “split thenm” after that spawn actor is not complaining about wrond transform anymore. You also can split all struct pins this way, just right click on them and split.
Haha, yeah people should think about other developers with Singleplayer Games that tell their users that a Multiplayer version is not planned right now, since it would need a complete rebuild of the game.
And that’s really true, Singleplayer and Multiplayer do need a complete different code structure which is, in Multiplayer, way heavier.
That’s why real beginners should stick to Singleplayer. Even if it is their dream to create a Multiplayer game. It will just end in a frustrated quit if you try to learn all at once.
Of course is only the beginning, but for me is a big BIG step, i was stuck from weeks !
Now i trying to replicate the pawn movement for the client to the other clients (and the server), i thought to get the vector of the actor, write on a vector variable and then send all to the server that will update the position (for every players), is my logic correct ? Because i’m sure the pratice is not lol.
If i test the print string (vector) on the player 2 they work very well, but when i tried to print string on the server with a call of the position (posizione) = fail. The two target reference are linked to the return value of the spawn 2player, i don’t know why but i suspect that i’m wrong here.