So I have started a new project with the Code Third Person startup kit, I was reading about replication and how the pawns are automatically synched if replication is enabled, so I start two clients on one client I can move with point and click fine, on the other client however no pawn is loaded and instead the camera just stays in the middle of the level, I know both clients are connected because when on the client which has the pawn loaded I move to a location in front of the camera on client B I can see that the pawn is being synched properly.
On another note disabling the playercontroller and defaultpawn override in C++ actually makes it work, both clients connect to eachother in first person.
So my question is, what am I doing wrong? And why isnt the same process that creates the pawn for the first client not creating the pawn on the second connect client?
I am fairly new to Unreal so this is probably something trivial I have missed out.
Elyanar - can you try this: move the first client away from the starting spawn point, then type ‘reconnect’ on the second client. I noticed a bug in the third person code template where respawning doesn’t retry if the initial attempts. This is a work around until that bug can be fixed.
At a quick glance, just adding a new spawn point doesn’t fix the issue. The problem is in the actual spawning / player controller state machine code (The server is never trying extra spawn points, or trying to respawn when the client clicks). I will need to dig a little deeper. This is working in some of our other games (Shooter game for example).
That seems to be a problem, although I dont know how there must be a way to assign another spawnpoint or a spawn position. Thank you very much for the help!
What I did do get this to work was to override ChoosePlayerStart() in the gamemode class and from there you can return an appropriate starting location. If you iterate over all SpawnPoints (this is an TArray where all the starting position are stored) and check if there is a collision, if not return that player start location else keep looking. There is an example of this in the Shooter game, check the functions ChoosePlayerStart(), IsSpawnpointAllowed() and IsSpawnpointPreferred() in ShooterGameMode.h.
The entire code you need to add to your Game Mode class is right here:
This is from the shootergame example!
I use this code in my own project and I know it works for real multiplayer open ip games
#ShooterGame Game Mode Class
#.h
/** select best spawn point for player */
virtual AActor* ChoosePlayerStart(AController* Player) OVERRIDE;
/** check if player can use spawnpoint */
virtual bool IsSpawnpointAllowed(APlayerStart* SpawnPoint, AController* Player) const;
/** check if player should use spawnpoint */
virtual bool IsSpawnpointPreferred(APlayerStart* SpawnPoint, AController* Player) const;
There is no reason to include the function below as you also have to create a new class “AShooterTeamStart”, and all it does is check if AI or player can spawn.
And the spawn points are still bugged, it seems that unless you repeatedly try to respawn the player, you will still get players re spawning on the same spawn point, not sure how shooter game is doing it, need to investigate.
This is very helpful and i have to ask… could you show how to use this code to actually spawn a player with a controller in the world??? i mean it gets you the spawnpoints - ok. but i’m having problems to spawn actors? i wanted to spawn a ‘local’ second player.
this would be very helpful